I am writing a class that inherits from IHttpHandler for script and css combining. I only want to combine if the querystring has a special parameter defined. If this parameter is not defined then I want to write the contents of the file as if the handler wasn’t even involved. What is the best way to deliver the file unharmed?
EIDT:
The one problem I’m encountering is that I have a script tag on the page that refers to a script in a virtual directory but the page I am on is in a subdirectory of the application.
The page that the control script is being referenced from is located at webserver/Admin/Default.aspx. When I access the Request object in the class that implements IHttpHandler all file path properties are the following: webserver/Admin/~/SharedScripts/control.js. How do I resolve this?
You can check the query string parameter in the ‘ProcessRequest(HttpContext context)’ method like this:
If you want to stream the requested file as is you can then do the following:
PS: You can also check out the following code project article for a more comprehensive example: http://www.codeproject.com/KB/locale/LocalizedScriptsAndStyles.aspx