如何确定HttpModules的执行顺序?

jes*_*vin 34 asp.net web-config httpmodule

假设双方FirstModuleSecondModule处理Application_BeginRequest事件.它会按web.config中定义的顺序执行吗?

<httpModules>
  <add type="MyApp.FirstModule, MyApp" name="FirstModule"/>
  <add type="MyApp.SecondModule, MyApp" name="SecondModule"/>
  <add type="OtherApp.OtherModule, OtherApp" name="OtherModule"/>
</httpModules>
Run Code Online (Sandbox Code Playgroud)

是否有其他方式可以指定订单?

M4N*_*M4N 35

根据这篇论坛帖子,HttpModules按照注册顺序执行.这对我来说很有意义,因为否则<clear><remove> 指令也不会按预期工作,例如当这样使用时:

<httpModules> 
   <clear/>
   <add... />
</httpModules>
Run Code Online (Sandbox Code Playgroud)

  • 不应该依赖它是,不是因为它不起作用,而是因为设计考虑并促进模块之间的松散耦合.但是,没有任何情况下模块的排序与配置文件中的顺序不同.希望这可以帮助. (8认同)
  • 论坛里有人发帖这么说的。然而也有几个人说你不应该依赖它。 (2认同)