I have a .Net 4.5 Web API 2 application that runs fine locally through Visual Studio on IIS Express but does not run when deployed to a server.
The deployed server is 2008 R2 SP1 with IIS 7.5 and .Net 4.5.2 installed.
On the deployed website when I go to the root instead of showing the default route, "home/index", it gives a 403 forbidden error because it's trying to do directory browsing, which is turned off. If I enter the route /home/index or any other of the valid Web API routes that I have defined I get a 404 Not Found error.
As I said, all of the routes work fine locally under IIS Express, but on the IIS 7.5 server it does not recognize URL Routing at all and is treating my Web API deployed service as a classic website.
I've done considerable searching on this problem and in most cases it is solved by adding some entries to the System.webServer section of the web.config:
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true" />
<handlers>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="UrlRoutingModule-4.0"/>
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
<add name="UrlRoutingModule-4.0" path="*" verb="*" type="System.Web.Routing.UrlRoutingModule" preCondition=""/>
</handlers>
</system.webServer>
However, this does not make a difference in my case. What else would prevent URL Routing from working in a Web API app on IIS?