The asp.net Application_AcquireRequestState event caused the Ajax client to fail to load

  • 2020-05-07 19:33:27
  • OfStack

The next 1 cut of IIS7 is normal in the development environment, but after the deployment to IIS6 server, the Ajax client cannot load every time the page is refreshed.
 
protected void Application_AcquireRequestState(object sender, EventArgs e) 
{ 
string oldToken = Session["token"].ToString(); 
} 

MSDN says: Application_AcquireRequestState, which is executed when ASP.NET gets the current state associated with the current request, such as Session.
However, the reality is that when we use the AJAX control, a page fires this event multiple times, and Session appears as NULL.
The reason is that some scripts and images are parsed by webresource.axd handler, but when multiple scripts and images are used on one page, the page will request more than one time.
This event is triggered multiple times.
Therefore, to access Session in an event, you need to first determine whether Session is NULL.
Or, let's first determine the type of request.
 
if (Request.Url.AbsoluteUri.Contains(".axd") || Request.Url.AbsoluteUri.Contains(".asmx")) 
return; 

Hold for two days, release, mark 1.

Related articles: