该篇文章是我于2009年6月10日通过自己编写的工具,批量从位于在博客园的博客站点(http://chenxizhang.cnblogs.com)同步而来。文章中的图片地址仍然是链接到博客园的。特此说明! 陈希章原文地址:http://www.cnblogs.com/chenxizhang/archive/2008/08/27/1277274.html原文标题:关于HttpModule事件顺序和执行顺序 原文发表:2008/8/27 0:40:00 |
总的来说,有如下事件会依次触发。
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)
"OutputCache" type=
"System.Web.Caching.OutputCacheModule"/>
"Session" type=
"System.Web.SessionState.SessionStateModule"/>
"WindowsAuthentication" type=
"System.Web.Security.WindowsAuthenticationModule"/>
"FormsAuthentication" type=
"System.Web.Security.FormsAuthenticationModule"/>
"PassportAuthentication" type=
"System.Web.Security.PassportAuthenticationModule"/>
"RoleManager" type=
"System.Web.Security.RoleManagerModule"/>
"UrlAuthorization" type=
"System.Web.Security.UrlAuthorizationModule"/>
"FileAuthorization" type=
"System.Web.Security.FileAuthorizationModule"/>
"AnonymousIdentification" type=
"System.Web.Security.AnonymousIdentificationModule"/>
"Profile" type=
"System.Web.Profile.ProfileModule"/>
"ErrorHandlerModule" type=
"System.Web.Mobile.ErrorHandlerModule, System.Web.Mobile, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
"ServiceModel" type=
"System.ServiceModel.Activation.HttpModule, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
作者:陈希章 出处:http://blog.youkuaiyun.com/chen_xizhang 本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。 |