Today, we create a vb.net login instance. The foreground uses Ajax in Ext. The background uses the ashx file to process the login process and stores the user in the Session. This error always occurs. [NullReferenceException: object reference is not set to the instance of the object.]
I checked it online for the following reasons:
1. The ViewState object is Unll.
2. DateSet is empty.
3. DataReader is empty due to SQL statements or Datebase.
4. When a string variable is declared without a null value, the variable is applied.
5. The new initialization object is not used.
6. The Session object is empty.
At first, the reason was that the Session object was empty: Modify the following code:
If context. Session. isNewSession then
Context. Session ("UserName") = username 'username is the user name accepted
.................
After the modification, the system will be dizzy !!!!!, The same error. Google again.
Input: It is too difficult to search the ashx processing session. It seems that searching also requires a lot of skills.
Originally: to use Session in ashx, The System. Web. SessionState. IRequiresSessionState interface must be inherited. The IHttpHandler interface is inherited by default.
OK. Check the source code directly.
Copy codeThe Code is 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