Overriding IIS6 wildcard maps on individual directories
ASP.NET, MVC, Routing July 7th, 2008Many thanks to Duncan Smart whose comment on my previous post about deploying ASP.NET MVC applications to IIS 6 gives us a further option. It turns out that even though IIS Manager only lets you configure wildcard maps on a per-application level, IIS itself allows you to configure them on a per-directory level.
Recap: The goal here is to deploy ASP.NET MVC applications to IIS 6, keeping the clean, extensionless URLs (which requires a wildcard map so that all URLs are processed by ASP.NET, or some tricky URL-rewriting), but without incuring the performance penalty of letting static files get processed by ASP.NET. See the previous post for more details.
So, if you can be disciplined and keep all your static content inside your /Content folder, you can use a normal wildcard map at the root level to get ASP.NET MVC to handle all incoming URLs, even without any “filename extensions” in the URLs, but then also disable that wildcard map on the /Content folder and below, allowing those static files to be processed natively by IIS (which performs much better).
How to set it up
First, deploy your application and use a wilcard map as explained before. Next, find out the “identifier” of your application by looking at IIS Manager:
Now, to remove the wildcard map on the /Content subdirectory, open a command prompt, go to c:\Inetpub\AdminScripts, and run:
adsutil.vbs SET /W3SVC/105364569/root/Content/ScriptMaps ""
… replacing 105364569 with the “identifier” number of your application. (Also, you could replace “Content” with the path to any other directory.)
That does it! Your /Content folder will now bypass the wildcard mapping, and its files will be served natively by IIS.
Alternative
If you don’t like to use adsutil.vbs, you can achieve the same by exploiting what appears to be a bug in IIS Manager. Turn your subdirectory into an application (from its Directory tab, click “Create”). Then edit its script mappings to remove aspnet_isapi.dll. Then go back and “Remove” the application you just created. The metabase’s new ScriptMaps value will be retained, even though the option has now disappeared from the GUI.


July 19th, 2008 at 6:12 pm
Nice post, you got some good points there - thank you.
July 25th, 2008 at 1:30 pm
Yeeeeaaaaahhhhhh!!!! It works perfectly even on Windows XP :)))) Thanks very much!!! :)))
July 25th, 2008 at 1:42 pm
One more thing. I run Fiddler and check content headers. For static files IIS send proper headers and IE (Firefox too) caches files - IIS responds 304.
How it is possible? Maybe StaticFileHandler is smarter now?
July 27th, 2008 at 7:32 pm
OMFG! After fighting with this for nearly 2 months on and off, your solution has finally solved this issue for me. THANK YOU VERY MUCH!!!
August 20th, 2008 at 12:35 pm
You could also use Metabase Explorer (included in the IIS 6 Resource Kit) [http://support.microsoft.com/kb/840671#8] to edit the IIS metabase
August 29th, 2008 at 3:04 am
Thank you! This has greatly increased performance in one of our servers running IIS 6