天天看点

AjaxPro使用Session出错(AjaxPro "Session"引发了"System.NullReferenceException"类型的异常)

关于在ASP.NET如何使用AjaxPro,这里就不多说了,先看代码:

    [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]

    public string btnNextZX(string data)

    {

        StringBuilder zx_Ret = new StringBuilder();

        Hashtable hash = (Hashtable)Session["jgd_data"];

AjaxPro使用Session出错(AjaxPro "Session"引发了"System.NullReferenceException"类型的异常)
AjaxPro使用Session出错(AjaxPro "Session"引发了"System.NullReferenceException"类型的异常)

注意:这里排除Session中没有["jgd_data"]这个数据而引起的出错,当然即使不存在也报的并不是如下的错误:

很奇怪!我明明加了如下代码啊!!

[AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]

将如下代码行:

Hashtable hash = (Hashtable)Session["jgd_data"];

替换成如下代码:

Hashtable hash = (Hashtable)HttpContext.Current.Session["jgd_data"];

继续阅读