locked
Web API 2 URL routing 404 error on IIS 7.5 - IIS Express works fine RRS feed

  • Question

  • User190540780 posted

    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" />
          <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" />
        </handlers>
      </system.webServer>

    However, this does not make any difference in my case.

    I have all the latest updates installed on the server using Windows Update.  I have verified that under Roles, Web Server (IIS) that Http Errors and Http Redirection are installed.

    Here is the error detail:

    <fieldset><legend>Error Summary</legend>

    HTTP Error 404.0 - Not Found

    The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

    </fieldset>
    <fieldset><legend>Detailed Error Information</legend>
    Module IIS Web Core
    Notification MapRequestHandler
    Handler StaticFile
    Error Code 0x80070002
    Requested URL http://localhost:80/MDChoice.EnrollmentPortal.WebApi/Home/Index
    Physical Path C:\Inetpub\wwwroot\MDChoice.EnrollmentPortal.WebApi\Home\Index
    Logon Method Anonymous
    Logon User Anonymous
    </fieldset>

    What else would prevent URL Routing from working on IIS?

    Tuesday, October 6, 2015 1:02 PM

Answers