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

2020-01-24 06:38发布

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>

30条回答
等我变得足够好
2楼-- · 2020-01-24 07:01

In my case, the issue was simply that I was trying to access the site at

myserver.myintranet.com/mysite

But the web site binding for http in IIS didn't have the host name specified in the binding. It had worked before and I have no idea how that got blown away.

Once I put myserver.myintranet.com into the host name the 404 was gone.

In IIS Manager you go into Bindings... in the actions pane, then edit the http binding to specify the host name.

查看更多
太酷不给撩
3楼-- · 2020-01-24 07:02

Had the same issue, a 404 response for the web api controllers when served from the IIS but everything worked fine from VS2010. None of the above solutions worked for me. Eventually I found that the problem was that we added WSE 3.0 support for the application and the Microsoft.Web.Services3 dll was missing in the application's /bin directory. Weird, but after copying the dll, the route mapping started to work.

查看更多
对你真心纯属浪费
4楼-- · 2020-01-24 07:05

I recently had a 404 not found error with all my Web Api 2 routes/controllers. So I went onto the actual server and tried to browse using localhost instead of the hostname and got "404.7 Not Found - The request filtering module is configured to deny the file extension".

This SO post help me solve it.

查看更多
Root(大扎)
5楼-- · 2020-01-24 07:07

I had a similar problem. I had the right settings in my web.config file but was running the application pool in Classic mode rather than Integrated mode

screen shot

查看更多
够拽才男人
6楼-- · 2020-01-24 07:11

i do nothing, just add this tag in web.config, its working this issue come up one of the following points

  1. Use Web Api in the same project using MVC or asp.net forms

  2. Use RouteConfig and WebApiConfig in Global.asax as GlobalConfiguration.Configure(WebApiConfig.Register); RouteConfig.RegisterRoutes(RouteTable.Routes);

  3. Use RouteConfig for 2 purposes, asp.net forms using with friendlyurl and mvc routing for MVC routing

we just use this tag in web.config, it will work.

<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
   .........................
</modules>
</system.webServer>
查看更多
SAY GOODBYE
7楼-- · 2020-01-24 07:11

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.
查看更多
登录 后发表回答