在IIS 7.5中托pipe的Web Api中找不到HTTP 404页面

我有一个Web Api应用程序。 当我使用VS 2010debugging开发服务器进行testing时,它工作得非常好。 但是我现在将它部署到IIS 7.5,并且在尝试访问应用程序时遇到HTTP 404错误。

这是我的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> 

我也在为此苦苦挣扎。 幸运的是,Steve Michelottilogging了一个在我这里工作的解决scheme。

在一天结束时,我启用了所有的动词(动词=“*”)到我的webconfiguration中的ExtensionlessUrlHandler-Integrated-4.0处理程序。

 <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> 

其他人指出,启用WebDAV会导致问题。 幸运的是,我也没有遇到这个问题。

有同样的问题。 这个configuration设置解决了这个问题。

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

正如http://www.britishdeveloper.co.uk/2010/06/dont-use-modules-runallmanagedmodulesfo.html解释的解决scheme应该避免。; 改用这个。 Lopsided也提供了相同的解决scheme。 保持在这里让用户避免实施第一个工作解决scheme。

 <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 eg FormsAuthentication, Roles etc. --> </modules> 

如果在ASP.NET之后安装或启用了IIS,则需要手动向IIS注册ASP.NET以使.NET应用程序能够正常工作。

对于Windows 7和更早版本:

  1. 以pipe理员身份运行命令提示符(cmd.exe)。
  2. 导航到相应的.NET Framework位置。 (例如C:\ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319)
  3. 运行aspnet_regiis.exe -i

对于Windows 8和更高版本:

  1. 从开始菜单中,input“打开或closures窗口function”并select第一个结果。
  2. 展开Internet信息服务:万维网服务:应用程序开发function并selectASP.NET 4.5(或ASP.NET 3.5,如果需要支持.NET Framework 2.0-3.5上的项目)。
  3. 点击OK。

你在虚拟目录或应用程序中运行Web API应用程序吗?

例如:当我将我的项目移动到默认网站> SampleWebAPI下的本地IIS时,我遇到了同样的问题。 我相信这是由于URL路由的变化,如下所示:

原文: localhost:3092/api/values
移动了: localhost/SampleWebAPI/api/values

如果您将Web API项目移动到运行在其他端口上的自己的网站,它似乎工作。

附加说明:我通过添加api作为我的网站内的一个应用程序的别名,导致有效的URL是:

localhost:81/api/api/values – 将网站移至自己的网站后注意到这一点

因此,因为我想保持我的网站和web api mvc项目站点之间的分离,我将API的“DefaultAPI”的global.asax的路由规则从api/{controller}/{id}更改为{controller}/{id}和ASP.NET MVC之一Default{controller}/{id}info/{controller}/{id}

几件事情来检查:

  1. 确保你已经安装了.NET Framework 4。
  2. 确保为您的网站和虚拟目录select了.NET Framework的版本4(如果适用)。
  3. 确保你已经安装了MVC,或者在你的bin目录下有合适的DLL。
  4. 可能需要允许ASP.NET 4.0 Web服务扩展
  5. 把应用程序放在它自己的应用程序池中。
  6. 确保目录至less具有“仅脚本”执行权限。

这是为我工作的唯一答案…

我有一个类似的问题…似乎不pipe我做了什么,没有得到redirect,我的全局文件被忽略。 我认真考虑过在我find答案之前就结束了这一切。 我希望这个链接可以帮助别人。

  • 堆栈溢出 – 在IIS 7和ASP.NET MVC上诊断404错误

将以下内容添加到web.config文件适用于我:

 <system.webServer> <modules> <remove name="UrlRoutingModule-4.0" /> <add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" /> </modules> </system.webServer> 

当然, system.webServer标记已经存在,但是我添加了模块标记,然后删除添加标记到模块标记。

由于以下原因,也可能发生此问题

1.在Web.Config中

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

2.确保部署Web API的服务器上的bin文件夹中具有以下内容

  • System.Net.Http

  • System.Net.Http.Formatting

  • System.Web.Http.WebHost

  • System.Web.Http

如果通过Visual Studio进行发布,这些程序集将不会被复制到bin文件夹中,因为Web API软件包是通过开发机器中的Nuget安装的。 如果您想要将这些文件作为Visual Studio发布的一部分提供,那么您需要将CopyLocal设置为True以用于这些assembly

萨迪什Kumar.V

我有一个类似的问题。 我在我的web.config文件中有正确的设置,但是以经典模式而不是集成模式运行应用程序池

屏幕截图

我也遇到了这个问题。 我通过转到应用程序池>应用程序池名称解决了这个问题,并将.NET Framework从版本v.2.0.50727更改为v4.0.30319。

有来自微软的官方修复: http : //support.microsoft.com/kb/980368

我强烈build议不要使用<modules runAllManagedModulesForAllRequests =“true”>。 这导致所有请求(甚至是.jpg,.css,.pdf等)都将被所有注册的HTTP模块处理。 有两个负面的时刻:a)硬件资源上的额外负载; b)潜在的错误,因为http模块将处理新types的内容。

我遵循一个Windows Azure教程,告诉我在我的项目中添加一个“WebRole.cs”文件,开始从Web API获得404响应。

从我的项目中删除“WebRole.cs”后,我的Web API调用再次开始工作。

请确保应用程序池处于集成模式
并将以下内容添加到web.config文件中:

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

有同样的问题,404服务器响应的Web API控制器从IIS服务,但从VS2010一切正常工作。 上述解决scheme都不适合我。 最终,我发现问题是我们添加了WSE 3.0对应用程序的支持,并且在应用程序的/ bin目录中缺less了Microsoft.Web.Services3 dll。 奇怪,但复制dll后,路线映射开始工作。

我必须禁用文件发布选项“预发布期间预编译”。

就我而言,这个问题只是我试图访问该网站

myserver.myintranet.com/mysite

但是,在IIS中绑定http的网站没有绑定中指定的主机名。 它曾经工作过,我不知道如何被吹走。

一旦我把myserver.myintranet.com放入主机名,404就不见了。

在IISpipe理器中,进入操作窗格中的绑定… ,然后编辑http绑定以指定主机名。

基于这个答案 ,我只需要改变path="*."path="*"用于在我的web.configconfiguration>system.WebServer>handlers中添加的ExtensionlessUrlHandler-Integrated-4.0

之前:

 <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /> 

后:

 <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*" verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /> 

不要忘记部署global.asax

你正在做什么样的HTTP请求?

这是一个稍微左的领域的答案,但你有没有尝试删除404的IIS默认错误页面来检查你的API实际返回?

我有一个问题,我想要一个控制器方法返回一个404,当我张贴错误的ID到它。 我发现我总是得到IIS 404“文件或目录未find”页面,而不是来自我的API的HTTP响应。 删除默认的404错误页面解决了这个问题。

不同的问题,但你永远不知道它可以帮助;)

web.config文件中的这一段configuration可以帮助我:在system.webServer部分:

  <security> <requestFiltering> <verbs applyToWebDAV="true"> <remove verb="PUT" /> <add verb="PUT" allowed="true" /> <remove verb="DELETE" /> <add verb="DELETE" allowed="true" /> <remove verb="PATCH" /> <add verb="PATCH" allowed="true" /> </verbs> </requestFiltering> </security> 

我最近有一个404未find所有我的Web Api 2路由/控制器的错误。 所以我去了实际的服务器,并试图浏览使用本地主机而不是主机名,并得到“404.7未find – 请求过滤模块configuration为拒绝文件扩展名”。

这SOpost帮我解决它。

它为我解决了,当启用UrlRoutingModule-4.0checkbox:

IISpipe理器>模块>selectUrlRoutingModule-4.0>编辑模块>选中“仅调用对ASP.NET应用程序或托pipe处理程序的请求”checkbox。

我有同样的问题:在Visual Studio 2013新安装的计算机上,web api项目在IISExpress下工作,但不在本地IIS下。 我尝试了所有可以find的东西,但是最终,Web API没有必要解决这个问题,但是使用MVC:即使安装了它,也没有任何MVC项目正在运行。

什么对我来说是卸载IIS(从添加/删除Windowsfunction),然后重新安装,然后运行aspnet_regiis -i。 也许这有助于别人。

我花了大量的时间尝试了很多事情,终于意识到我不是在站点/默认网站中添加我的networking应用程序,而是在另一个绑定到另一个端口的网站上。 显然,在80端口上尝试localhost会给404。

我什么都不做,只要在web.config中添加这个标签,它的工作就出现了以下几点之一

  1. 使用MVC或asp.net表单在同一个项目中使用Web Api

  2. 在Global.asax中使用RouteConfig和WebApiConfig作为GlobalConfiguration.Configure(WebApiConfig.Register); RouteConfig.RegisterRoutes(RouteTable.Routes);

  3. 使用RouteConfig有2个用途,asp.net表单使用friendlyurl和mvc路由用于MVC路由

我们只是在web.config中使用这个标签,它会工作。

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