Click here to Skip to main content
15,890,043 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:


XML
<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?
Posted
Comments
Zouzou_J 27-Jan-16 15:57pm    
Were you able to fix this issue at the end?

1 solution

Yes, the problem was that we had an old build script for a classic ASP.Net app and so it was not publishing the Views and Areas folders. Once we had all the .cshtml files on the server it worked fine.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900