ASP.NET Routing not working on IIS 7.0
I ran into a nasty little problem today when deploying an application using ASP.NET 4.0 Routing to my live server. The application and its Routing were working just fine on my dev machine (Windows 7 and IIS 7.5), but when I deployed (Windows 2008 R1 and IIS 7.0) Routing would just not work. Every time I hit a routed url IIS would just throw up a 404 error:
This is an IIS error, not an ASP.NET error so this doesn’t actually come from ASP.NET’s routing engine but from IIS’s handling of expressionless URLs. Note that it’s clearly falling through all the way to the StaticFile handler which is the last handler to fire in the typical IIS handler list. In other words IIS is trying to parse the extension less URL and not firing it into ASP.NET but failing.
As I mentioned on my local machine this all worked fine and to make sure local and live setups match I re-copied my Web.config, double checked handler mappings in IIS and re-copied the actual application assemblies to the server. It all looked exactly matched. However no workey on the server with IIS 7.0!!!
Finally, totally by chance, I remembered the runAllManagedModulesForAllRequests attribute flag on the modules key in web.config and set it to true:
<system.webServer> <modules runAllManagedModulesForAllRequests="true"> <add name="ScriptCompressionModule" type="Westwind.Web.ScriptCompressionModule,Westwind.Web" /> </modules> </system.webServer>
And lo and behold, Routing started working on the live server and IIS 7.0!
This seems really obvious now of course, but the really tricky thing about this is that on IIS 7.5 this key is not necessary. So on my Windows 7 machine ASP.NET Routing was working just fine without the key set. However on IIS 7.0 on my live server the same missing setting was not working. On IIS 7.0 this key must be present or Routing will not work.
Oddly on IIS 7.5 it appears that you can’t even turn off the behavior – setting runtAllManagedModuleForAllRequests="false" had no effect at all and Routing continued to work just fine even with the flag set to false, which is NOT what I would have expected.
Kind of disappointing too that Windows Server 2008 (R1) can’t be upgraded to IIS 7.5. It sure seems like that should have been possible since the OS server core changes in R2 are pretty minor. For the future I really hope Microsoft will allow updating IIS versions without tying them explicitly to the OS. It looks like that with the release of IIS Express Microsoft has taken some steps to untie some of those tight OS links from IIS. Let’s hope that’s the case for the future – it sure is nice to run the same IIS version on dev and live boxes, but upgrading live servers is too big a deal to do just because an updated OS release came out.
Moral of the story – never assume that your dev setup will work as is on the live setup. It took me forever to figure this out because I assumed that because my web.config on the local machine was fine and working and I copied all relevant web.config data to the server it can’t be the configuration settings. I was looking everywhere but in the .config file forever before getting desperate and remembering the flag when I accidentally checked the intellisense settings in the modules key.
Never assume anything. The other moral is: Try to keep your dev machine and server OS’s in sync whenever possible. Maybe it’s time to upgrade to Windows Server 2008 R2 after all.
More info on Extensionless URLs in IIS
Want to find out more exactly on how extensionless Urls work on IIS 7? The check out How ASP.NET MVC Routing Works and its Impact on the Performance of Static Requests which goes into great detail on the complexities of the process. Thanks to Jeff Graves for pointing me at this article – a great linked reference for this topic!
The Voices of Reason
# re: ASP.NET Routing not working on IIS 7.0
"On IIS 7.0 this key must be present or Routing will not work"
We found that this setting is not required to get routing working in Server 2008 IIS 7.0. Originally we did have runAllManagedModulesForAllRequests="true" and Routing was working, then we found this post about why using that setting is not a good idea:
http://www.britishdeveloper.co.uk/2010/06/dont-use-modules-runallmanagedmodulesfo.html
We found that if we applied KB980368 (requires Windows Server 2008 SP2) we could get Routing to work without relying on runAllManagedModulesForAllRequests.
# re: ASP.NET Routing not working on IIS 7.0
Unless your site(s) are super critical in terms of resource usage, I'd say the overhead of having all requests going through the module pipeline is not that critical. Other than initial startup slowness for an ApplicationPool and first access performance is not likely to have more than a fractional percentage impact. I suppose it depends on your app and what module filtering occurs on requests, but if we're talking only about the routing module (and default ASP.NET pipeline modules) the overhead is really small. Plus IIS caching will override for a lot of requests served from disk.
# re: ASP.NET Routing not working on IIS 7.0
# re: ASP.NET Routing not working on IIS 7.0
# re: ASP.NET Routing not working on IIS 7.0
I also refer very helpful and useful article about URL Routing in ASP.Net 3.5(IIS7)
Please visit this helpful article
http://www.mindstick.com/Articles/9992a0bc-90f5-4f04-823a-31f901b61643/URL%20Routing%20in%20ASP%20Net%203%205%20IIS7#.VfkUMpc0Xcc
http://stackoverflow.com/questions/2226610/configuring-iis-7-asp-net-app-for-url-routing
# re: ASP.NET Routing not working on IIS 7.0
You da man! I was trying to figure out the same thing. I assumed that the 2008 was running 7.5 as well and all was identical, but apparently not.
# re: ASP.NET Routing not working on IIS 7.0
Found the following KB: http://support.microsoft.com/kb/980368
I installed the fix in the KB (which requires an OS restart).
It fixed the problem for us.
Gilles
# re: ASP.NET Routing not working on IIS 7.0
# re: ASP.NET Routing not working on IIS 7.0
Thanks a lot you saved me many hours by your great blog post!
# re: ASP.NET Routing not working on IIS 7.0
# re: ASP.NET Routing not working on IIS 7.0
We had one customer with Windows Server 2008 Standard version 6.0 build 6002 SP2, IIS 7.0.* which 404ed on all requests for bundled files.
We concluded that the problem was IIS7.0. The KB patch refused to install - said it wasn't needed, so we tried your fix and that works perfectly.
# re: ASP.NET Routing not working on IIS 7.0
# re: ASP.NET Routing not working on IIS 7.0
I think it's because on Windows Server 2008 (my development machine), Visual Studio already applies the patch or does something else that makes it work. On the Windows 7 machine that did NOT have Visual Studio installed, it failed to work, untill we added the line in Web.config.
# re: ASP.NET Routing not working on IIS 7.0
Today, you saved my friday evening. In other projects i had to add the modules part for other libraries, in this one i didn't need and i would have never guessed the link. Thanks !
# re: ASP.NET Routing not working on IIS 7.0
@txcraig and others let us to a working solution.
Adding the specific module needed worked for us. We had the "evil" runAllManagedModulesForAllRequests="true" attribute, but didn't want to use it because of the performance concerns (and should you just run all really?). Simply adding the correct module, and removing that evil attribute solved the problem.
We didn't install the patch for Windows 2008 SP2, IIS 7.0 we wanted to try to work around that.
<modules>
<remove name="BundleModule" />
<add name="BundleModule" type="System.Web.Optimization.BundleModule" />
</modules>
# re: ASP.NET Routing not working on IIS 7.0
I am able to perform GET and POST request through WebAPI on LocalHost development server via AJAX .
After deployment to IIS server on AWS I am not at all able to perform GET and POST through AJAX.( I have referred your articles related to WebAPI and ASP.Net passing multiple parameters and like others)
I have noticed following points after deployment to IIS Server.
1) when I typed URL for WebAPI I am able to get JSON data as expected from AWS.
2) AJAX returning error on POST and GET request
3) Fiddler returns JSON data as expected for GET
Is it related to ASP.Net Routing ?
Appreciate your time and guidance.
# re: ASP.NET Routing not working on IIS 7.0
Just want to add that a hotfix http://support.microsoft.com/kb/980368 did solve the problem, plus we removed everything from webserver section
<system.webServer>
</system.webServer>
# re: ASP.NET Routing not working on IIS 7.0
I have got same problem on server. Probably this was because you are using MVC/ Routing in ASP.NET 4.0.
My problem was solved mere by changing Appllication pool to ASP.NET 4.0 for that website/application & restarting site on IIS.
Hope it can work at other side too.
# re: ASP.NET Routing not working on IIS 7.0
http://support.microsoft.com/kb/2520479
As a web hoster this really buggered things up for us and is still unresolved :(.
# re: ASP.NET Routing not working on IIS 7.0