Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to deal with Session problem in ashx File by Asp.net

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report