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:
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With