关于HttpModule事件顺序和执行顺序

本文详细解释了HTTP模块中的事件顺序及其执行流程,并通过实例展示了当注册多个HTTP模块时,这些事件是如何按特定顺序被触发的。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

该篇文章是我于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
本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值