четверг, 8 октября 2009 г.

HttpApplication.Init method

HttpApplication class has a method  Init. It is virtual and called by ASP.NET runtime when initializing of a HttpApplication is almost finished i.e. all modules have been initialized and all event handlers in the Global.asax have been registered. It is also lat time when you can attach handlers to the HttpApplication events. The method is quite handy if you want to place your custom HttpApplication in a separate  class library project.

I’ve used it to see which modules are registered for an application and subscribed for the application events,  and how much time each stage of the request processing takes. The output looks like the following.

See attached file

Modules HttpApplication event handlers Timing
OutputCache
Session
WindowsAuthentication
FormsAuthentication
PassportAuthentication
RoleManager
UrlAuthorization
FileAuthorization
AnonymousIdentification
Profile
ErrorHandlerModule
ServiceModel
DefaultAuthentication
BeginRequest
  ASP.global_asax.Application_BeginRequest

AuthenticateRequest
  System.Web.Security.WindowsAuthenticationModule.OnEnter
  System.Web.Security.PassportAuthenticationModule.OnEnter

DefaultAuthentication
  System.Web.Security.DefaultAuthenticationModule.OnEnter

PostAuthenticateRequest
  System.ServiceModel.Activation.HttpModule.ProcessRequest

AuthorizeRequest
  System.Web.Security.UrlAuthorizationModule.OnEnter
  System.Web.Security.FileAuthorizationModule.OnEnter

ResolveRequestCache
  System.Web.Caching.OutputCacheModule.OnEnter

AcquireRequestState
  System.Web.Profile.ProfileModule.OnEnter

AcquireRequestStateAsync 
   System.Web.SessionState.SessionStateModule.BeginAcquireState 
   System.Web.SessionState.SessionStateModule.EndAcquireState

ReleaseRequestState
  System.Web.SessionState.SessionStateModule.OnReleaseState

UpdateRequestCache
  System.Web.Caching.OutputCacheModule.OnLeave

EndRequest
  System.Web.SessionState.SessionStateModule.OnEndRequest
  System.Web.Security.PassportAuthenticationModule.OnLeave
  System.Web.Profile.ProfileModule.OnLeave
Stage From BeginRequest From Last Stage
ticks ms ticks ms
BeginRequest
AuthenticateRequest 13 .01 13 .01
DefaultAuthentication 20 .01 7
PostAuthenticateRequest 45 .02 25 .01
AuthorizeRequest 79 .04 34 .02
PostAuthorizeRequest 84 .04 5
ResolveRequestCache 91 .04 7
PostResolveRequestCache 96 .05 5
PostMapRequestHandler 179 .08 83 .04
AcquireRequestState 214 .1 35 .02
PostAcquireRequestState 220 .1 6
PreRequestHandlerExecute 225 .11 5
PostRequestHandlerExecute 309 .15 84 .04
ReleaseRequestState 318 .15 9
PostReleaseRequestState 323 .15 5
UpdateRequestCache 331 .16 8
PostUpdateRequestCache 336 .16 5
EndRequest 344 .16 8