HTTP 404 Page Not Found in Web Api hosted in IIS 7.5

I have a Web Api application. It works perfectly well when I tested it using the VS 2010 debugging dev server. But I now deployed it to IIS 7.5 and I am getting a HTTP 404 error when trying to access the application.

Here is my web.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=aspnet-FlowGearProxy-20123141219;Integrated Security=True" providerName="System.Data.SqlClient" />
  </connectionStrings>
  <appSettings>
    <add key="webpages:Version" value="2.0.0.0" />
    <add key="webpages:Enabled" value="true" />
    <add key="PreserveLoginUrl" value="true" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <authentication mode="Forms">
      <forms loginUrl="~/Account/Login" timeout="2880" />
    </authentication>
    <pages>
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages" />
      </namespaces>
    </pages>
  </system.web>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true" />
  </system.webServer>
</configuration>

I was struggling with this as well. Fortunately, Steve Michelotti documented a solution that worked for me here.

At the end of the day, I enabled all verbs (verb="*") to the ExtensionlessUrlHandler-Integrated-4.0 handler in my web config.

<system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true" />
        <handlers>
            <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
            <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" />
        </handlers>
</system.webServer>

Others have pointed out that having WebDAV enabled causes issues. Fortunately, I did not run into that issue as well.


Had same issue. This configuration setting solved the issue.

<system.webServer>
    .....
    <modules runAllManagedModulesForAllRequests="true" />
    .....
</system.webServer>

As explained in http://www.britishdeveloper.co.uk/2010/06/dont-use-modules-runallmanagedmodulesfo.html above solution should be avoided. Use this instead. Same solution is provided by Lopsided also. Keeping it here to let users avoid implementing the first working solution.

<modules>
  <remove name="UrlRoutingModule-4.0" />
  <add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
  <!-- any other modules you want to run in MVC e.g. FormsAuthentication, Roles etc. -->
</modules>

If IIS is installed or enabled after ASP.NET, you will need to manually register ASP.NET with IIS in order for your .NET application to work.

For Windows 7 and earlier:

  1. Run the Command Prompt (cmd.exe) as an administrator.
  2. Navigate to the appropriate .NET Framework location. (e.g. C:\Windows\Microsoft.NET\Framework64\v4.0.30319)
  3. Run aspnet_regiis.exe -i

For Windows 8 and later:

  1. From the start menu, type "Turn windows features on or off" and select the first result.
  2. Expand Internet Information Services: World Wide Web Services: Application Development Features and select ASP.NET 4.5 (or ASP.NET 3.5 if you need to support projects on .NET Framework 2.0-3.5).
  3. Click OK.

Are you running the Web API app in a virtual directory or an application?

For example: I had the same issue when I moved my project to my local IIS under the Default Web Site > SampleWebAPI. I believe this is due to the change in the URL routing as follows:

Original: localhost:3092/api/values
Moved: localhost/SampleWebAPI/api/values

If you move the Web API project to it's own website running on a different port it seems to work.

Additional note: I had further complicated the issue by adding api as the alias of an application within my website which caused the effective URL to be:

localhost:81/api/api/values - noticed this after moving the website to it's own website

Therefore, because I wanted to maintain a separation between my website and the web api mvc project site, I changed the routing rules in global.asax for the Web API "DefaultAPI" from api/{controller}/{id} to {controller}/{id} and the ASP.NET MVC one Default from {controller}/{id} to info/{controller}/{id}.