How is the order of execution for HttpModules determined?

jessegavin picture jessegavin · Mar 11, 2010 · Viewed 9.3k times · Source

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?

Answer

M4N picture M4N · Mar 11, 2010

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>