views:

305

answers:

2

I wrote a dynamic image resizer as a HttpHandler. It's automatically called on anything with an image extension, so for example:

http://www.mysite.com/picture.jpg?width=200&height=100

will run the handler and return a thumbnail image with the proper response headers. However, I want the handler to let a request 'pass through' if it's called without a querystring:

http://www.mysite.com/picture.jpg

I want this to return the image with the header information like it would be if it didn't run it through the handler. Is this possible without having to manually code in the header information (which involves opening filestreams to read data such as last written date), or do I have to convert my handler to a HTTPModule instead?

+1  A: 

Couldn't you just adjust your handler to account for this case? You could just make sure there are no query string parameters and just map the request path to disk and return the image directly by opening it and just write it to the output stream.

Jon
The problem there is that I'd have to set all the header info myself rather than having the web server take care of it.Actually, the main reason why I wanted to avoid doing this was because I thought that I had to open the file in order to get the last write-to date. I didn't realize `File.GetLastWriteTimeUtc(file)` does the same thing until now.
Daniel T.
+1  A: 

A handler has to "handle" the request. It's the end of the chain. You either need to make it an HttpModule, or you need to serve the image yourself, whether or not you resize it.

John Saunders
That's what I had a feeling what the handler had to do. Thanks for confirming it!
Daniel T.