我有一个Web Api应用程序。当我使用VS2010调试开发服务器测试它时,它工作得很好。但我现在将其部署到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>
发布于 2012-04-19 12:11:23
我也在为此而苦苦挣扎。幸运的是,Steve Michelotti记录了一个适用于我的here的解决方案。
最后,我在我的web配置中启用了所有动词(verb="*")到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会导致问题。幸运的是,我也没有遇到这个问题。
发布于 2013-01-22 19:05:09
也有同样的问题。此配置设置解决了此问题。
<system.webServer>
.....
<modules runAllManagedModulesForAllRequests="true" />
.....
</system.webServer>
正如上面http://www.britishdeveloper.co.uk/2010/06/dont-use-modules-runallmanagedmodulesfo.html中所解释的,应该避免使用解决方案。改用这个。Lopsided也提供了相同的解决方案。保留它是为了让用户避免实现第一个有效的解决方案。
<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>
发布于 2012-03-27 10:53:32
您是否在虚拟目录或应用程序中运行Web API应用程序?
例如:当我将我的项目移动到我的本地IIS的Default Web Site > SampleWebAPI下时,我遇到了同样的问题。我相信这是由于URL
路由的改变,如下所示:
原创:localhost:3092/api/values
已移动:localhost/SampleWebAPI/api/values
如果您将Web API项目移动到它自己的网站上运行在不同的端口上,它似乎可以工作。
补充说明:我在我的网站中添加了api
作为应用程序的别名,从而导致有效的URL
为:
localhost:81/api/api/values
-在将网站移动到自己的网站后注意到了这一点
因此,因为我希望在我的网站和Web API MVC项目站点之间保持分离,所以我在global.asax
中将web api "DefaultAPI“的路由规则从api/{controller}/{id}
更改为{controller}/{id}
,将ASP.NET mvc one Default
从{controller}/{id}
更改为info/{controller}/{id}
。
https://stackoverflow.com/questions/9703090
复制相似问题