Today do a vb.net login instance, the foreground uses the EXT Ajax, the backstage uses the Ashx file to process the login process, and the user stores in the session always appears in this error. [NullReferenceException: Object references are not set to an instance of an object. ]
Check it from the Internet for several reasons:
1, ViewState object is UNLL.
2, Dateset empty.
3, the SQL statement or datebase causes DataReader empty.
4. When declaring a string variable, the variable is applied without null value.
5, the object is not initialized with new.
6, the Session object is empty.
Reason to start thinking that the session object is empty: Modify the code below
If context. Session.isnewsession Then
Context. Session ("UserName") =username ' UserName for accepted username
.................
After this modification, Halo!!!!!, is still the same mistake. Google it.
Input: ASHX processing session in the search, too difficult, it seems that search also requires a lot of skills
Original: In ashx to use session, you need to inherit the System.Web.SessionState.IRequiresSessionState interface. The default inherits the IHttpHandler interface
OK, just look at the source code.
Copy Code code as follows:
<%@ 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 format data
End Sub
Public ReadOnly Property IsReusable () as Boolean Implements ihttphandler.isreusable
Get
Return False
End Get
End Property
End Class