0

I'm using forms authentication in my current asp.net web forms application "not MVC" and wondering if Global.asax [Application_AuthenticateRequest] and [Application_PostAuthenticateRequest] invoked on every request to the server or Not? i mean does ajax calls count for Global.asax handling or some bugs might occur! because i found in this link conflict:

http://channel9.msdn.com/forums/TechOff/256322-Strangeness-between-ASPNET-AJAX-and-Globalasax/

so please advice if its good or bad to handle custom authentication for ajax calls through Global.asax

thanks,

Jawad Al Shaikh
  • 2,475
  • 2
  • 28
  • 41

1 Answers1

1

AJAX calls back to your application are just the same as hitting the site with the browser so yes these events will be fired.

The article you link to concerns the scenario where you have more than one request made within the same session.

http://msdn.microsoft.com/en-us/library/ms178581.aspx

Access to ASP.NET session state is exclusive per session, which means that if two different users make concurrent requests, access to each separate session is granted concurrently. However, if two concurrent requests are made for the same session (by using the same SessionID value), the first request gets exclusive access to the session information. The second request executes only after the first request is finished.

So if you made two requests back to your application from ajax code running in the browser they would be executed one after the other, not in parallel.

There is no way to turn this feature off.

In ASP.NET MVC3 it is possible to create sessionless controllers that do permit multiple ajax requests in the same session to be serviced at the same time by decorating the controller with this attribute:

[SessionState(SessionStateBehavior.Disabled)]
Kev
  • 118,037
  • 53
  • 300
  • 385
  • so i can say its safe/proper to use global.asax events to do something like redirecting as shown in this question:http://stackoverflow.com/questions/1879136/forms-authentication-and-post-requests-from-ajax – Jawad Al Shaikh Apr 22 '11 at 10:37
  • or if there is better way you can advice I'll appreciate that! – Jawad Al Shaikh Apr 22 '11 at 10:37
  • If it's some fairly simple stuff that's one-off then I don't see why not. If you plan to re-use the code then maybe a [HttpModule](http://msdn.microsoft.com/en-us/library/ms227673.aspx) may be a better choice. – Kev May 03 '11 at 00:36