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
December 2nd, 2008 at 6:46 pm
I am trying to use option 1 but it is not working. The regular 404 page still gets invoked and asp.net does not show the asp.net “resource is missing” page. Any suggestions what I could have done wrong?
December 3rd, 2008 at 9:21 am
Natalie, one possibility is that you haven’t enabled ASP.NET (in IIS Manager’s Web Service Extensions)
March 3rd, 2009 at 3:19 pm
Steve -
To be frank… you’re the man when it comes to MVC! Days of frantic playing about, and then your blog comes to to the rescue (not for the first time I should say). I’m paying a visit to Amazon…
April 16th, 2009 at 11:54 am
Thanks for finding this workaround!
I’ve used it in a bit different way: for enabling wildcard ASP.NET processing on a specific folder and it worked. So root and all folders except “X” are processed as usually, but all requests to “X” get passed to aspnet_isapi.dll.
May 7th, 2009 at 7:07 am
[…] There is a separate post which talks about improving the performance of this method, which is worth implementing: Disabling wildcard mapping on subdirectories […]