Creating custom IHttpModules, I have realized that the requests for static files (e.g.: .css and .js files) are hitting the managed modules. Probably pictures have the same problem. Shouldn't IIS bypass ASP.NET for files that exists in the filesystem?
For example:
public class MyModule:IHttpModule
{
public void Dispose(){ }
public void Init(HttpApplication context)
{
context.BeginRequest += (o, e) => Debug.Print("Request: " + HttpContext.Current.Request.RawUrl);
}
}
And I declare it this way:
<modules runAllManagedModulesForAllRequests="true">
<add name="MyModule" preCondition="managedHandler" type="MVCX.Modules.MyModule, MVCX"/>
</modules>
But, even using the precondition I can see how the static files goes through the module:
Request: /MVCX/
Request: /MVCX/Content/Site.css
Request: /MVCX/Scripts/jquery-1.4.4.min.js
I have tried to ignore the rules for static files, but it does not make a difference:
routes.IgnoreRoute("{Content}/{*pathInfo}");
routes.IgnoreRoute("{Scripts}/{*pathInfo}");
Is this the usual? Or am I missing something here? As far as I know, if the static file request should be answered by IIS. If my managed module is being hit, means that a CLR ThreadPool thread is handling that request, right?
Regards.
UPDATE:
I have disabled the "runAllManagedModulesForAllRequests":
<modules runAllManagedModulesForAllRequests="false">
<add name="MyModule" preCondition="managedHandler" type="MVCX.Modules.MyModule, MVCX" />
</modules>
And everything seems to work just fine, but I have found this article: http://www.britishdeveloper.co.uk/2010/06/dont-use-modules-runallmanagedmodulesfo.html that recommends remove and readd the "UrlRoutingModule-4.0" module with an empty precondition.
I my machine, the adding of that module is in the root web.config, and it has already an empty preCondition:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config>type machine.config | find "UrlRouting"
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config>type web.config | find "UrlRouting"
<add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" />
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config>
So now I am a little bit confused, what is the status of this parameter? Should I use it or shouldn't? why does it come as "true" by default?
Regards.