总的来说,有如下事件会依次触发。
BeginRequest
AuthenticateRequest
AuthorizeRequest
ResolveRequestCache
AcquireRequestState
PreRequestHandlerExecute
PostRequestHandlerExecute
ReleaseRequestState
UpdateRequestCache
EndRequest
此外,有三个不确定的顺序:
PreSendRequestHeaders
PreSendRequestContent
Error
那么,当我们注册了多个Module之后会怎么样呢?
举个例子:
如果你在web.config配置了两个HttpModule,分别是HttpModuleA,HttpModuleB
这个事件执行的顺序如下:
HttpModuleA->BeginRequest
HttpModuleB->BeginRequest
HttpModuleA->AuthenticateRequest
HttpModuleB->AuthenticateRequest
HttpModuleA->AuthorizeRequest
HttpModuleB->AuthorizeRequest
...以此类推
当然了,系统默认的那些Module总是在自定义Module之前执行
Framework中默认的Module(C:\windows\microsoft.net\Framework\v2.0.50727\CONFIG\web.config)
<httpModules> <add name="OutputCache" type="System.Web.Caching.OutputCacheModule"/> <add name="Session" type="System.Web.SessionState.SessionStateModule"/> <add name="WindowsAuthentication" type="System.Web.Security.WindowsAuthenticationModule"/> <add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule"/> <add name="PassportAuthentication" type="System.Web.Security.PassportAuthenticationModule"/> <add name="RoleManager" type="System.Web.Security.RoleManagerModule"/> <add name="UrlAuthorization" type="System.Web.Security.UrlAuthorizationModule"/> <add name="FileAuthorization" type="System.Web.Security.FileAuthorizationModule"/> <add name="AnonymousIdentification" type="System.Web.Security.AnonymousIdentificationModule"/> <add name="Profile" type="System.Web.Profile.ProfileModule"/> <add name="ErrorHandlerModule" type="System.Web.Mobile.ErrorHandlerModule, System.Web.Mobile, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/> <add name="ServiceModel" type="System.ServiceModel.Activation.HttpModule, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/> </httpModules>