今天做一个vb.net的登录实例,前台使用Ext中Ajax ,后台用ashx文件处理登录过程,并将用户储存在Session中总是出现在这个错误. [NullReferenceException: 未将对象引用设置到对象的实例。]
.................
原来:在 ashx 中要使用Session ,需要继承System.Web.SessionState.IRequiresSessionState接口.默认的之继承了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格式数据
End Sub
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class