title: ASP.NET Web Api 2 breaks on IIS 7.5
body: <p>I have a very small AngularJS web application that I've written and that I am trying to host on IIS locally on my machine so that it is available to other devices on my LAN. In this application I am using Web API 2 calls for data access which is hooked up to my database via Entity Framework.</p>
  
  <p>The application runs fine when I run it locally by starting it in Visual Studio. However, when I deploy it to my installation of IIS I get 404 errors whenever a request is sent to a Web API url. The page itself loads and I can navigate to my other pages, it is only when a request is made to one of the methods I have declared in my Web API controller that I receive the 404 errors.</p>
  
  <p>I have Windows 7 Pro 64-bit and installed IIS via the Add / Remove Windows features in control panel. I have installed ASP.NET 4.0 via the aspnet_regiis -i command. When publishing I am doing so in Visual Studio Community 2015 by right clicking on the project and selecting Publish. I used a guide from the official ASP.NET site when setting up to publish for the first time (<a href="http://www.asp.net/mvc/overview/deployment/visual-studio-web-deployment/deploying-to-iis" rel="nofollow noreferrer">http://www.asp.net/mvc/overview/deployment/visual-studio-web-deployment/deploying-to-iis</a>)</p>
  
  <p>I've tried the following steps to resolve the issue with no success:</p>
  
  <ol>
  <li>Uninstall / Re-installing IIS via Add / Remove Windows Features</li>
  <li>Adding <code>&lt;validation validateIntegratedModeConfiguration="false" /&gt;</code> and <code>&lt;modules runAllManagedModulesForAllRequests="true" /&gt;</code> to the web.config</li>
  <li>Changing the path (by removing the period) on the <code>&lt;add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /&gt;</code> handler defined in web.config</li>
  <li>Manually adding the ApiURIs-ISAPI-Ingegrated-4.0 handler to the web config</li>
  <li>Adding <code>&lt;remove name="UrlRoutingModule" /&gt;</code> and <code>&lt;add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule" preCondition=""/&gt;</code> to the <code>&lt;system.webServer&gt;</code> modules section</li>
  <li>Double checking that my application pool is set to integrated mode and is set to use .Net Framework v4.0.30319</li>
  <li>Applying the official Microsoft Hotfix available at <a href="https://support.microsoft.com/en-us/kb/980368" rel="nofollow noreferrer">https://support.microsoft.com/en-us/kb/980368</a> Upon attemtping to install this hotfix it states that it is not compatible with my computer. </li>
  <li>Making sure that my computer is up to date with the latest windows updates</li>
  <li>Unchecking the "Invoke only for requests to ASP.NET applications on managed handlers" checkbox for the UrlRoutingModule-4.0 module found via Sites --> Default Web Site --> Modules in IIS section --> Bindings option right hand side under Actions</li>
  <li>Verifying that the System.Net.Http, System.Net.Http.Formatting, System.Web.Http.WebHost and System.Web.Http assemblies are all present in the bin folder for the site</li>
  </ol>
  
  <p>I've been all over the interwebs looking for a solution for close to two days now and have yet to find one. There appear to be a number of similar questions on the site from people experiencing the same issue but none of the several I've found have solved the issue thus far.  </p>
  
  <p>It seems utterly ridiculous to me that it should take this much effort for this to work in the way it is supposed to out of the box. Any help you can provide I would greatly appreciate. </p>
  
  <p>TL;DR: Web API 2 breaks when deployed with an AngularJS application to IIS 7.5. See list above for steps taken to attempt to remedy. </p>
  
  <p><strong>UPDATE 1</strong></p>
  
  <p>I have attempted to set up Failed Request Tracing using the following links from IIS.net:</p>
  
  <ol>
  <li><a href="http://www.iis.net/learn/troubleshoot/using-failed-request-tracing/troubleshooting-failed-requests-using-tracing-in-iis" rel="nofollow noreferrer">http://www.iis.net/learn/troubleshoot/using-failed-request-tracing/troubleshooting-failed-requests-using-tracing-in-iis</a></li>
  <li><a href="http://www.iis.net/learn/troubleshoot/using-failed-request-tracing/using-failed-request-tracing-rules-to-troubleshoot-application-request-routing-arr" rel="nofollow noreferrer">http://www.iis.net/learn/troubleshoot/using-failed-request-tracing/using-failed-request-tracing-rules-to-troubleshoot-application-request-routing-arr</a></li>
  </ol>
  
  <p>This returns a log file with an warning which looks like this<a href="https://i.stack.imgur.com/Wo4In.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Wo4In.png" alt=""></a></p>
  
  <p>Here is a snipet from the Complete Trace Request. I would be happy to provide the full file if needed.
  <a href="https://i.stack.imgur.com/3j16K.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3j16K.png" alt=""></a></p>
  
  <p><strong>UPDATE 2</strong></p>
  
  <p>Removing WebDAV via Add/Remove features does not solve the problem. The error is the same "file can not be found" error as above and here is the new snippet from the Complete Trace Request
  <a href="https://i.stack.imgur.com/xQKhQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xQKhQ.png" alt=""></a></p>
  
  <p>My WebApiConfig class looks like the following</p>
  
  <pre><code>public static class WebApiConfig
  {
      public static void Register(HttpConfiguration config)
      {
          // Web API configuration and services
  
          // Web API routes
          config.MapHttpAttributeRoutes();
  
          config.Routes.MapHttpRoute(
              name: "DefaultApi",
              routeTemplate: "api/{controller}/{id}",
              defaults: new { id = RouteParameter.Optional }
          );
      }
  }
  </code></pre>
  
  <p>My Web API class looks like </p>
  
  <pre><code>[RoutePrefix("api/foods")]
  public class FoodsController : ApiController
  {
  
      [Route("all")]
      [HttpGet]
      public List&lt;tblFood&gt; getAllFoods()
      {
          List&lt;tblFood&gt; foodsList = new List&lt;tblFood&gt;();
  
          try
          {
              using (FoodEntities dbContext = new Entity_Models.FoodEntities())
              {
                  foodsList = (from food in dbContext.tblFoods select food).ToList();
              }
          }
          catch(EntityException e)
          {
              throw new ApplicationException(createErrorStringFromException(e));
          }
  
          return foodsList;
      }
  }
  </code></pre>
  
  <p>A sample call from my angular JS service uses the call</p>
  
  <pre><code>$http.get('/api/foods/all')
  </code></pre>
  
  <p>There are a few other CRUD methods declared in my class but all of which are declared in the same way and which I have left out of the code above for brevity. I have been using the "all" route as my test.</p>
  
  <p>I used the resources <a href="http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api" rel="nofollow noreferrer">http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api</a> and <a href="http://www.asp.net/web-api/overview/web-api-routing-and-actions/attribute-routing-in-web-api-2" rel="nofollow noreferrer">http://www.asp.net/web-api/overview/web-api-routing-and-actions/attribute-routing-in-web-api-2</a> when setting up routing.</p>