0

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:

  1. Uninstall / Re-installing IIS via Add / Remove Windows Features
  2. Adding <validation validateIntegratedModeConfiguration="false" /> and <modules runAllManagedModulesForAllRequests="true" /> to the web.config
  3. 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
  4. Manually adding the ApiURIs-ISAPI-Ingegrated-4.0 handler to the web config
  5. Adding <remove name="UrlRoutingModule" /> and <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule" preCondition=""/> to the <system.webServer> modules section
  6. Double checking that my application pool is set to integrated mode and is set to use .Net Framework v4.0.30319
  7. 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.
  8. Making sure that my computer is up to date with the latest windows updates
  9. 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
  10. 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:

  1. http://www.iis.net/learn/troubleshoot/using-failed-request-tracing/troubleshooting-failed-requests-using-tracing-in-iis
  2. 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.

Josh
  • 23
  • 5
  • Do you have **all** of the sub-features of IIS installed? A default installation of IIS on Windows desktop excludes many built-in features for some reason, you need to manually check all of the checkboxes in the Ad/Remove Features dialog. – Dai May 07 '16 at 23:18
  • @Dai Yes, I have installed all of the sub-features. Even the ones I don't need like the FTP Server and IIS 6 Management Compatibility. The only IIS related item that is listed in the Add / Remove Features that I don't have installed is the IIS Hostable Web Core which is listed separately. – Josh May 07 '16 at 23:54
  • 1
    Have you tried Failed Request Tracing? When you're using Visual Studio to run the app have you tried configuring it to use Local IIS instead of IIS Express? Are you using a subdirectory for your application? If so, have you set-up the necessary Virtuals and Application Scopes? – Dai May 08 '16 at 00:08
  • @Dai This morning I tried having Visual Studio use Local IIS and I receive the same 404 errors. I have set up Failed Request Tracing and tried looking at that but it appears to just tell me that the system can't find the file. I read up on a couple articles on it from IIS.net (see the updated post for the links to the articles) and nothing jumps out of the logs at me. I'd be happy to post them if needed. I'm unsure if I'm am using a sub-directory or how to tell if I am. To create the site I followed the steps in the link my original post since this is my first time using IIS. – Josh May 08 '16 at 15:14
  • "Can't find the file" - what file is it looking for? ASP.NET Web API uses URI Routing, so there is no correspondence between the URI-path requested and any filesystem path - if it is looking for the URI-path in the filesystem then it means you don't have routing set-up correctly. – Dai May 08 '16 at 22:57
  • @Dai It should not be looking for a file, I was puzzled as to why it states that it is looking for a file as well. It should be hitting a method declared in my controller class using the GET method. I have further updated the question with the new snippet of the trace log and the details of how I have Web API configured as well as the sources that I followed when configuring it. – Josh May 09 '16 at 00:38

1 Answers1

0

The Failed Request tracing log shows that IIS is invoking WebDAV to handle the request, which suggests the request is made using a PUT method, for example.

Disable the WebDAV module and try again. Follow this guide: http://www.asp.net/web-api/overview/testing-and-debugging/troubleshooting-http-405-errors-after-publishing-web-api-applications

And this QA: ASP.NET Web API - PUT & DELETE Verbs Not Allowed - IIS 8

Community
  • 1
  • 1
Dai
  • 141,631
  • 28
  • 261
  • 374