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.
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.
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 (http://www.asp.net/mvc/overview/deployment/visual-studio-web-deployment/deploying-to-iis)
I've tried the following steps to resolve the issue with no success:
- Uninstall / Re-installing IIS via Add / Remove Windows Features
- Adding
<validation validateIntegratedModeConfiguration="false" />
and<modules runAllManagedModulesForAllRequests="true" />
to the web.config - Changing the path (by removing the period) on the
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
handler defined in web.config - Manually adding the ApiURIs-ISAPI-Ingegrated-4.0 handler to the web config
- Adding
<remove name="UrlRoutingModule" />
and<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule" preCondition=""/>
to the<system.webServer>
modules section - Double checking that my application pool is set to integrated mode and is set to use .Net Framework v4.0.30319
- Applying the official Microsoft Hotfix available at https://support.microsoft.com/en-us/kb/980368 Upon attemtping to install this hotfix it states that it is not compatible with my computer.
- Making sure that my computer is up to date with the latest windows updates
- 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
- 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
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.
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.
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.
UPDATE 1
I have attempted to set up Failed Request Tracing using the following links from IIS.net:
- http://www.iis.net/learn/troubleshoot/using-failed-request-tracing/troubleshooting-failed-requests-using-tracing-in-iis
- http://www.iis.net/learn/troubleshoot/using-failed-request-tracing/using-failed-request-tracing-rules-to-troubleshoot-application-request-routing-arr
This returns a log file with an warning which looks like this
Here is a snipet from the Complete Trace Request. I would be happy to provide the full file if needed.
UPDATE 2
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
My WebApiConfig class looks like the following
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 }
);
}
}
My Web API class looks like
[RoutePrefix("api/foods")]
public class FoodsController : ApiController
{
[Route("all")]
[HttpGet]
public List<tblFood> getAllFoods()
{
List<tblFood> foodsList = new List<tblFood>();
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;
}
}
A sample call from my angular JS service uses the call
$http.get('/api/foods/all')
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.
I used the resources http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api and http://www.asp.net/web-api/overview/web-api-routing-and-actions/attribute-routing-in-web-api-2 when setting up routing.