Cannot Stop ASP.NET Module Launch for Static Content

I have a module in an ASP.NET MVC application. The module works fine, but it starts for each type of file, including static content, although I have:

<modules runAllManagedModulesForAllRequests="false"> <add name="MyModule" ... / > </modules> 

The module hooks the AcquireRequestState and PostRequestHandlerExecute events, and both show a static content trigger (.htm, .css, .png, etc.).

I got the impression that runAllManagedModulesForAllRequests = "false" should contain modules for crawling nonASP.NET content.

To clarify:

I can set preCondition = "managedHandler" as follows:

 <add name="MyModule" type="MyApp.MyModule" preCondition="managedHandler" /> 

and get my module to run only managed requests.

However, I am trying to understand why the IIS pipeline as a whole runs remote remote modules for each request. I think this worked very well in older versions, unless runAllManagedModulesForAllRequests = "true" did not run unmanaged content in ASP.NET modules.

Runs on IIS8 in 64-bit mode of Windows 8 with integrated pipeline mode.

Update:

After several more studies, it turns out that the following is true:

  • if runAllManagedModulesForAllRequests = "true" of all modules - regardless of whether the preCondition attribute is set for all requests. This is also true for implementing Application_XXXX events in HttpApplication
  • runAllManagedModulesForAllRequests = "false" does not affect unmanaged requests from remote modules unless preCondition = "managedHandler" is set
  • runAllManagedModulesForAllRequests = "false" affects Application_XXXX events, as a result of which these events fire only managed requests. IOW, Application_XXXX behaves as if preCondition = "managedHandler" was in the implementation of the "module"

For more 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

+6
source share
1 answer

In IIS7, Microsoft introduced a new way to develop modules and handlers using managed (.NET) code, not just native code. The problem is switching the request between managed and native code, which is very expensive, so Microsoft introduced preCondition="managedHandler" . It places the module as accessible only for managed content requests (.aspx, .asmx, ...), so IIS avoids running it for static content.

Now you may have a situation when you want to change a static content request, for example, on the fly. You can write a module using C # and compile it as a managed module, but you want it to run for static content, so you just don't mark it as managedHandler .

Finally, runAllManagedModulesForAllRequests="true" used to override preCondition="managedHandler" , so they all start.

More information is available at:
http://www.iis.net/learn/get-started/introduction-to-iis/iis-modules-overview#Precondition

+7
source

All Articles