Can't stop firing ASP.NET Module for static content
asp.net, iis
Solution
In IIS7 Microsoft introduced a new way of developing modules and handlers by using managed (.NET) code, not just native code. Problem is switching a request between managed and native code is very expensive, so Microsoft introduced the `preCondition="managedHandler"`. It flags the module as only available for managed content requests (.aspx, .asmx, ...) so IIS avoids firing it for static content.
Now, you can have a situation where you want to modify an static content request, such as minifying JavaScript on the fly. You can write the module using C# and compile it as a managed module, but you want it to be fired for static content, so you simply do not mark it as `managedHandler`.
Finally, `runAllManagedModulesForAllRequests="true"` is used to override `preCondition="managedHandler"` so all of them get fired.
There is more info available at: http://www.iis.net/learn/get-started/introduction-to-iis/iis-modules-overview#Precondition
Problem
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: ``` <modules runAllManagedModulesForAllRequests="false"> <add name="MyModule" ... / > </modules> ``` The module hooks AcquireRequestState and PostRequestHandlerExecute events and both show static content firing (.htm, .css, .png etc.). I was under the impression that runAllManagedModulesForAllRequests="false" should keep modules from firing on non-ASP.NET content. To clarify: I can set preCondition="managedHandler" like this: ``` <add name="MyModule" type="MyApp.MyModule" preCondition="managedHandler" /> ``` and get my module to fire only managed requests. 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. Running on IIS8 on Windows 8 64 bit mode, with integrated pipeline mode. Update: After some more research it turns out that the following is true: - 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 - runAllManagedModulesForAllRequests="false" has no effect of keeping unmanaged requests from hitting modules, unless preCondition="managedHandler" is set - 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" For more detailed information on this I posted a blog entry: http://www.west-wind.com/weblog/posts/2012/Oct/25/Caveats-with-the-runAllManagedModulesForAllRequests-in-IIS-78