I'm attempting to write, what i thought would be, a simple HttpModule to rewrite incoming requests like "/styles/{somerevisionnumber}foo.css" to a static file at "/styles/foo.css". (The purpose being to insert a file hash or file modified date values in place of {somerevisionnumber} when generating urls in my web application to force browsers to retrieve updated files immediately while being able to set my expiration caches far into the future.)
The key requirement I can't seem to accomplish is that after the url is rewritten I want the request to go through just as it would for any static file. Meaning I want the StaticCompressionModule to compress and cache the file once on the first request and return the cached gzipped file on future requests for these redirected urls.
(Note: I'm attempting this under Windows 7, IIS 7.5, .Net 4, Visual Studio 2010 Beta 2)
For experimental purposes, in my BeginRequest handler I have something that effectively is:
if(Context.Request.Path == "/styles/1foo.htm") {
Context.RewritePath("/styles/foo.htm");
}
The act of calling Context.RewritePath seems to make further processing of the request 'dynamic'. i.e. I've noticed if I enable dynamic HttpCompression I will get a gzipped response from 1foo.htm but having *only* static HttpCompression turned on gives me uncompressed responses for 1foo.htm but compressed responses for foo.htm.
Even if i were to change my code to:
if(Context.Request.Path == "/styles/foo.htm") {
Context.RewritePath("/styles/foo.htm");
}
Notice i'm 'rewriting' to the exact same url. The act of calling Context.RewritePath alone seems to cause the request not to go through the static file / compression modules.
Admittedly i don't understand a lot of intricacies going on here. Is this pipeline ordering issue? Do I need to specify my url rewriting module run earlier? Am i using the wrong technique to rewrite the url?
As I mentioned I thought this would be simple and I would really like to gain a better understanding of what is going on and how to accomplish this. Thanks for your help!
Thomas