How is the order of execution for HttpModules determined?

∥☆過路亽.° 提交于 2019-12-18 10:49:12

问题


Suppose that both FirstModule and SecondModule handle the Application_BeginRequest event. Will it execute in the order defined in the 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>

Are there other ways that the order can be specified?


回答1:


According to this forum post, HttpModules are executed in the order in which they were registered. This makes sense to me, because otherwise the <clear> and <remove> directives would also not work as expected, e.g. when used like this:

<httpModules> 
   <clear/>
   <add... />
</httpModules>



回答2:


According to the Internet Information Services (IIS) 7.0 Resource Kit book extract from Microsoft Press,

To resolve such relative ordering dependencies, the administrator can control the relative ordering of modules by changing the order in which they are listed in the modules section.

This works because the server uses the order in the modules configuration section to order module execution within each request processing stage. By placing module A before module B in the list, you can allow module A to execute before module B.



来源:https://stackoverflow.com/questions/2427451/how-is-the-order-of-execution-for-httpmodules-determined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!