Search code examples
asp.net-mvcajaxpage-lifecycleihttpmodulehttpapplication

Does BeginRequest fire everytime? Which HttpApplication events fire when? Is it different for Ajax?


I am a little confused about the HttpApplication events.

I have a SessionService* that is initialized from an HttpModule. The HttpModule subscribes to HttpApplication.BeginRequest.

In the module I create a new SessionService().

The constructor of the SessionService setsSessionService.ServiceId = Guid.NewGuid().

I am using jquery to send two ajax requests from a link being clicked on a webpage. Both of the links return JSON indicating the SessionService.ServiceId, and it is the same.

I don't know why this is happening, but my best guest is I am misunderstanding when the events fire, and that some of them don't fire every httprequest. Thanks for your help.

*the session service has nothing to do with the HttpSessionState object


Solution

  • BeginRequest fires on every request: whether it's Ajax or not, it's still a HTTP request.

    Be careful: new Guid() represents an all-zero GUID. You probably wanted to use Guid.NewGuid().