在方法中我将结构存储到HttpSession中:
HttpContext.Current.Session["search_headers"] = ra;
其中ra是我的自定义结构类型“replySearchAjax”。
在web方法中,属于同一名称空间,我正在尝试:
[WebMethod(EnableSession = true)]
public replySearchAjax RestorePhenSearchTable()
{
if (HttpContext.Current.Session["search_headers"] != null)
{
replySearchAjax aa = (replySearchAjax) HttpContext.Current.Session["search_headers"];
return aa;
}
但是带有类型转换的行
{"Message":"Specified cast is not valid."
"ExceptionType":"System.InvalidCastException"}
在产生异常的行的断点处检查会话变量,表明其内部是有效的replySearchAjax字段。
我如何让它发挥作用?提前谢谢!