Search code examples
asp.netquery-stringhttphandlerhttpmodulerequest.querystring

Is it possible to skip a HttpHandler if there is no querystring?


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?


Solution

  • 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.