title: Can't stop firing ASP.NET Module for static content
body: <p>I have a module in an ASP.NET MVC application. The module is working fine, but it's firing for every type of file including static content even though I have:</p>
  
  <pre><code>&lt;modules  runAllManagedModulesForAllRequests="false"&gt;
      &lt;add name="MyModule" ... / &gt;
  &lt;/modules&gt;
  </code></pre>
  
  <p>The module hooks AcquireRequestState and PostRequestHandlerExecute events and both show static content firing (.htm, .css, .png etc.).</p>
  
  <p>I was under the impression that runAllManagedModulesForAllRequests="false" should keep modules from firing on non-ASP.NET content.</p>
  
  <p>To clarify: </p>
  
  <p>I <strong>can</strong> set preCondition="managedHandler" like this:</p>
  
  <pre><code>&lt;add name="MyModule" type="MyApp.MyModule" preCondition="managedHandler" /&gt;
  </code></pre>
  
  <p>and get my module to fire only managed requests.</p>
  
  <p>However, I'm trying to understand why the IIS pipeline in general is firing managed module hits for every request. I think this used to work just fine in older versions where unless runAllManagedModulesForAllRequests="true" it wasn't firing unmanaged content into ASP.NET modules.</p>
  
  <p>Running on IIS8 on Windows 8 64 bit mode, with integrated pipeline mode. </p>
  
  <p><strong>Update:</strong></p>
  
  <p>After some more research it turns out that the following is true:</p>
  
  <ul>
  <li>if runAllManagedModulesForAllRequests="true" all modules - regardless of their preCondition attribute setting fire on all requests. This also true for Application_XXXX events implement on the HttpApplication</li>
  <li>runAllManagedModulesForAllRequests="false" has no effect of keeping unmanaged requests from hitting modules, <em>unless</em> preCondition="managedHandler" is set</li>
  <li>runAllManagedModulesForAllRequests="false" does affect Application_XXXX events, causing those events to only fire on managed requests then. IOW, Application_XXXX behaves as if the 'module' implementation had a preCondition="managedHandler"</li>
  </ul>
  
  <p>For more detailed information on this I posted a blog entry:
  <a href="http://www.west-wind.com/weblog/posts/2012/Oct/25/Caveats-with-the-runAllManagedModulesForAllRequests-in-IIS-78" rel="nofollow">http://www.west-wind.com/weblog/posts/2012/Oct/25/Caveats-with-the-runAllManagedModulesForAllRequests-in-IIS-78</a></p>