Monday, January 19, 2009

Setup Http Handler For a Particular Folder in IIS 5 and 6

The other day I was setting up my custom ASP.Net http handler in IIS 7. Easy and painless. Using IIS manager just go to the folder you like and configure it, a snap. I tried to do the same thing in IIS 5.1 (the same thing with IIS 6), but no such luck. If you want to do it in a virtual folder, then that's not a problem - it's easy to set it up. However I wanted to set it up on a particular subfolder - no luck, IIS manager does not give you that option.
I was handling .js files so setting the handler on the top folder was a bit of an inconvenience. Luckily it is just a limitation of the IIS manager, not the IIS itself. What you need is to get yourself Metabase explorer which is a part of the IIS 6.0 Resource Toolkit and do a simple surgery.
Here is what I did:
I added folders beneath my virtual directory - Test in this case (Scripts and Dynamic), and added ScriptMaps key:

Normally it would inherit ScriptMaps from Test folder something like this:

I want it to handle only .js files so I added the key ScriptMaps (since it was inherited from the virtual directory it was not showing up in the list of keys):
And added a value for my files:
or in plain text that is:
note the . (dot) at the beginning and the path to the ASP.Net isapi filter might be different on your machine.
And that's it, I am only handling files I want to be handled by me in this folder, I can setup other file types if I wish in future. You still need to register your http handler, slight variation to the explanation is to put Scripts\Dynamic\*.js (in this case) for path attribute value.
I will add post on how to set this programatically soon.