今天做一個vb.net的登錄實例,前臺使用Ext中Ajax ,后臺用ashx文件處理登錄過程,并將用戶儲存在Session中總是出現(xiàn)在這個錯誤. [NullReferenceException: 未將對象引用設(shè)置到對象的實例。]
.................
原來:在 ashx 中要使用Session ,需要繼承System.Web.SessionState.IRequiresSessionState接口.默認(rèn)的之繼承了IHttpHandler接口
%@ WebHandler Language="VB" Class="logout" %>
Imports System
Imports System.Web
Imports System.Web.SessionState
Public Class logout : Implements IHttpHandler, IRequiresSessionState
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
context.Session.Clear()
context.Response.Write("{'success':'true'}") 'JSON格式數(shù)據(jù)
End Sub
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class