Tuesday 22 March 2011

Asp.Net: Order of HttpApplication events

 Question:
What is the order of the application events in a asp.net 4.0 application.
I have a HttpModule that subscribes to appliation events, in what order ?



Answer:
An application raises events that can be handled by custom modules that implement the IHttpModule interface or by event handler code that is defined in the Global.asax file.

There is a solid article on msdn about the HttpApplication class.

The article states the following order of events:

BeginRequest
AuthenticateRequest
    PostAuthenticateRequest
AuthorizeRequest
    PostAuthorizeRequest
ResolveRequestCache
    PostResolveRequestCache
    PostMapRequestHandler
AcquireRequestState
    - Session is available here
    PostAcquireRequestState
PreRequestHandlerExecute

    The event handler is executed.

PostRequestHandlerExecute
ReleaseRequestState
    PostReleaseRequestState
    - After the PostReleaseRequestState event is raised, any existing response filters will filter the output.
UpdateRequestCache
    PostUpdateRequestCache
LogRequest .
    - This event is supported in IIS 7.0 Integrated mode and at least the .NET Framework 3.0
PostLogRequest
    - This event is supported IIS 7.0 Integrated mode and at least the .NET Framework 3.0
EndRequest
.

No comments: