UrlRoutingModule, StaticFileHandler and IIS6
Today I was making sure that GZIP and the HTTP Expires header was enabled on all the content of our new ASP.NET MVC application. We have a little bit of code in our Global.asax to set up compression and expires appropriately.
I was surprised to find that despite using wildcard-mapping and IIS6 (which would result in all HTTP requests being ‘visible’ to Global.asax in a regular WebForms application), that our stylesheets were no longer being setup correctly.
Fiddling with the HTTP Header Expires setting in IIS confirmed that the stylesheet file appeared to be processed directly by IIS, which I had previously thought was impossible when using wildcard + IIS6.
I also found it strange that an MVC application would differ compared to WebForms: my understanding was that the new System.Web.UrlRoutingModule simply passed on-disk files to the appropriate handler, in this case System.Web.StaticFileHandler.
However, with a bit of testing I found this was not the case: modifying the web.config with:
<system.web> <httpHandlers><add verb="*" path="*.css" type="System.Web.StaticFileHandler"/></httpHandlers> </system.web>
Resulted in the Global.asax processing the request. This blog post mentions the potential behaviour of System.Web.DefaultHttpHandler in terms of passing files back to IIS (though its not mentioned where or how this was learned), and indeed this does appear to be exactly the case in MVC.
Poking through System.Web.DefaultHttpHandler in Reflector its not clear to me how this actually works, but its clear from my testing that a typical MVC application will have its static on-disk files sent directly by IIS.