尝试执行“有效”强制转换时,ASP.NET会话对象会生成InvalidCastException

时间:2013-04-11 15:14:13

标签: asp.net session casting

在方法中我将结构存储到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字段。

我如何让它发挥作用?提前谢谢!

0 个答案:

没有答案
相关问题