天天看點

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"];

繼續閱讀