Arm*_*and 93 c# iis-7.5 http-status-code-404 asp.net-web-api
我有一个Web Api应用程序.当我使用VS 2010调试开发服务器测试它时,它运行得非常好.但我现在将其部署到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>
Run Code Online (Sandbox Code Playgroud)
Kev*_*man 90
我也在努力解决这个问题.幸运的是,史蒂夫米凯洛蒂记载,为我工作的解决方案在这里.
在一天结束时,我将所有动词(verb ="*")启用到我的Web配置中的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>
Run Code Online (Sandbox Code Playgroud)
其他人指出,启用WebDAV会导致问题.幸运的是,我也没有遇到过这个问题.
hem*_*tam 53
有同样的问题.此配置设置解决了该问题.
<system.webServer>
.....
<modules runAllManagedModulesForAllRequests="true" />
.....
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
如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>
Run Code Online (Sandbox Code Playgroud)
Bra*_*ano 35
如果在ASP.NET之后安装或启用了IIS,则需要手动向IIS注册ASP.NET才能使.NET应用程序正常工作.
对于Windows 7及更早版本:
对于Windows 8及更高版本:
小智 25
您是在虚拟目录或应用程序中运行Web API应用程序吗?
例如:当我将项目移动到默认网站> SampleWebAPI下的本地IIS时,我遇到了同样的问题.我相信这是由于URL路由的变化如下:
原文:已 localhost:3092/api/values
移动: localhost/SampleWebAPI/api/values
如果将Web API项目移动到在不同端口上运行的自己的网站,它似乎可以工作.
附加说明:我通过api在我的网站中添加作为应用程序的别名来进一步使问题复杂化,从而导致有效URL:
localhost:81/api/api/values - 将网站移动到自己的网站后注意到这一点
因此,因为我想保持我的网站和网页API MVC项目网站之间的分离,我改变了路由规则global.asax从用于Web API"DefaultAPI" api/{controller}/{id}以{controller}/{id}和ASP.NET MVC一个Default从{controller}/{id}到info/{controller}/{id}.
Lop*_*ded 14
这是唯一对我有用的答案......
我有一个类似的问题......似乎无论我做了什么,没有任何东西被重定向,我的全局文件被忽略了.在我找到这个答案之前,我认真考虑结束这一切.我希望这个链接有助于其他人.
将以下内容添加到web.config文件中对我有用:
<system.webServer>
<modules>
<remove name="UrlRoutingModule-4.0" />
<add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
</modules>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
system.webServer标签已经在那儿了,当然,但我增加了模块的标签给它,然后删除和添加标签模块标签.
Joe*_*rag 11
要检查的一些事项:
小智 6
由于以下原因,也可能发生此问题
1.在Web.Config中
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<system.webServer>
Run Code Online (Sandbox Code Playgroud)
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
Sadish Kumar.V
在此基础上SO答案,我不得不改变path="*.",以path="*"所添加ExtensionlessUrlHandler-Integrated-4.0的configuration>system.WebServer>handlers我web.config
之前:
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
Run Code Online (Sandbox Code Playgroud)
后:
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*" verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
222214 次 |
| 最近记录: |