How to deal with Session problem in ashx File by Asp.net
This article will explain in detail how Asp.net deals with Session in the ashx file. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
To make a login instance of vb.net, it is always an error to use Ajax in Ext in the foreground and ashx file in the background to handle the login process and store the user in Session. [NullReferenceException: the object reference is not set to an instance of the object.]
Look it up on the Internet for the following reasons:
1. The ViewState object is Unll.
2. DateSet is empty.
3. The sql statement or Datebase causes the DataReader to be empty.
4. Apply a string variable without a null value when declaring it.
5. The object is not initialized with new.
6. The Session object is empty.
At first I thought it was because the Session object was empty: modify the code as follows
If context.Session.isNewSession then
Context.Session ("UserName") = username 'username is the accepted user name
.
After this modification, the faint is still the same mistake. Google again.
Input: ashx processing session in the search, it is not easy, it seems that the search also requires a lot of skills
Originally: to use Session in ashx, you need to inherit the System.Web.SessionState.IRequiresSessionState interface. The default inherits the IHttpHandler interface
OK, just look at the source code.
The copy code is as follows:
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
On "Asp.net in the ashx file how to deal with Session problems" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, please share it out for more people to see.