title: Web API 2 URL routing 403/404 error on IIS 7.5
body: <p>I am implementing a RESTful web services host using ASP.Net 4.5 and Web Api 2 Attribute Routing.  I also included <a href="http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/creating-api-help-pages" rel="nofollow">Web Api Help Pages</a>.  When I run it locally through Visual Studio 2012 on IIS Express it works great and looks really cool; it displays the default /home/index page with an API menu that shows the documentation for all my RESTful API functions.  I have also tested all the API methods with SOAPUI and running locally everything works perfectly.</p>
  
  <p>But the URL routing absolutely refuses to work when deployed to IIS 7.5 on Windows 2008 Server R2.</p>
  
  <p>When I browse the site I get:</p>
  
  <p>403 - Forbidden: Access is denied.</p>
  
  <p>If I try the /home/index or any of the routes of my web api methods I get:</p>
  
  <p>404 - File or directory not found.</p>
  
  <p>I have installed .Net 4.5 on the server and then went to Windows\Microsoft.NET\Framework64 and ran:</p>
  
  <p>Aspnet_regiis -i</p>
  
  <p>iisreset</p>
  
  <p>I deployed my app to IIS and set the Application Pool to use .Net Framework v4.0.30319 and Managed pipeline mode: Integrated.</p>
  
  <p>I have the following settings in my web.config:</p>
  
  <pre><code>    &lt;system.web&gt;
      &lt;compilation debug="true" targetFramework="4.5" /&gt;
      &lt;httpRuntime targetFramework="4.5" /&gt;
      &lt;authentication mode="None" /&gt;
      &lt;pages&gt;
        &lt;namespaces&gt;
          &lt;add namespace="System.Web.Helpers" /&gt;
          &lt;add namespace="System.Web.Mvc" /&gt;
          &lt;add namespace="System.Web.Mvc.Ajax" /&gt;
          &lt;add namespace="System.Web.Mvc.Html" /&gt;
          &lt;add namespace="System.Web.Optimization" /&gt;
          &lt;add namespace="System.Web.Routing" /&gt;
          &lt;add namespace="System.Web.WebPages" /&gt;
        &lt;/namespaces&gt;
      &lt;/pages&gt;
    &lt;/system.web&gt;
    &lt;system.webServer&gt;
      &lt;validation validateIntegratedModeConfiguration="false" /&gt;
      &lt;modules runAllManagedModulesForAllRequests="true" /&gt;
      &lt;handlers&gt;
        &lt;remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" /&gt;
        &lt;remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" /&gt;
        &lt;remove name="ExtensionlessUrlHandler-Integrated-4.0" /&gt;
        &lt;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" /&gt;
        &lt;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" /&gt;
        &lt;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" /&gt;
      &lt;/handlers&gt;
      &lt;/system.webServer&gt;
  </code></pre>
  
  <p>I have tried many different variations on the web.config entries.  For example, the suggestion in <a href="http://www.britishdeveloper.co.uk/2010/06/dont-use-modules-runallmanagedmodulesfo.html" rel="nofollow">this post</a> does not work either:</p>
  
  <pre><code>&lt;modules&gt;
    &lt;remove name="UrlRoutingModule-4.0" /&gt;
    &lt;add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" /&gt;
    &lt;!-- any other modules you want to run in MVC e.g. FormsAuthentication, Roles etc. --&gt;
  &lt;/modules&gt;
  </code></pre>
  
  <p>Nor does changing the Handlers section like this have any effect:</p>
  
  <pre><code>&lt;handlers&gt;
    &lt;remove name="ExtensionlessUrlHandler-Integrated-4.0" /&gt;
    &lt;remove name="OPTIONSVerbHandler" /&gt;
    &lt;remove name="TRACEVerbHandler" /&gt;
    &lt;remove name="WebDAV" /&gt;
    &lt;add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /&gt;
    &lt;add name="MiniProfiler" path="mini-profiler-resources/*" verb="*" type="System.Web.Routing.UrlRoutingModule" resourceType="Unspecified" preCondition="integratedMode" /&gt;
  &lt;/handlers&gt;
  </code></pre>
  
  <p>I did try turning directory browsing on and then it showed the website contents just fine, so the 403 Forbidden error is because directory browsing was forbidden.  </p>
  
  <p>But I don't want to browse the contents, I want URL routing to work.  In RouteConfig.cs file I have a default route:</p>
  
  <pre><code>    routes.MapRoute(
          name: "Default",
          url: "{controller}/{action}/{id}",
          defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
  </code></pre>
  
  <p>So if URL routing were working then it should show the Home/Index view by default.</p>
  
  <p>I also tried adding an Index.html file to the site and that worked fine too.  So the website works fine as a website, but URL routing refuses to work. </p>