IIS 7.5上的Web API 2 URL路由404错误 - IIS Express正常工作 [英] Web API 2 URL routing 404 error on IIS 7.5 - IIS Express works fine

查看:71
本文介绍了IIS 7.5上的Web API 2 URL路由404错误 - IIS Express正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个.Net 4.5 Web API 2应用程序,可以通过IIS Express上的Visual Studio在本地运行,但在部署到服务器时不会运行。



部署的服务器是2008 R2 SP1,安装了IIS 7.5和.Net 4.5.2。



在部署的网站上,当我转到root而不是显示默认路由时, home / index,它给出了403禁止错误,因为它正在尝试进行目录浏览,这是关闭的。如果我输入路由/ home / index或我定义的任何其他有效Web API路由,我会收到404 Not Found错误。



正如我所说,在IIS Express下,所有路由都可以正常工作,但在IIS 7.5服务器上,它根本无法识别URL路由,并将我的Web API部署服务视为经典网站。



我已经对这个问题进行了大量的搜索,在大多数情况下,它通过在web.config的System.webServer部分添加一些条目来解决:





I have a .Net 4.5 Web API 2 application that runs fine locally through Visual Studio on IIS Express but does not run when deployed to a server.

The deployed server is 2008 R2 SP1 with IIS 7.5 and .Net 4.5.2 installed.

On the deployed website when I go to the root instead of showing the default route, "home/index", it gives a 403 forbidden error because it's trying to do directory browsing, which is turned off. If I enter the route /home/index or any other of the valid Web API routes that I have defined I get a 404 Not Found error.

As I said, all of the routes work fine locally under IIS Express, but on the IIS 7.5 server it does not recognize URL Routing at all and is treating my Web API deployed service as a classic website.

I've done considerable searching on this problem and in most cases it is solved by adding some entries to the System.webServer section of the web.config:


<system.webServer>
  <validation validateIntegratedModeConfiguration="false" />
  <modules runAllManagedModulesForAllRequests="true" />
  <handlers>
    <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
    <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
    <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
    <remove name="UrlRoutingModule-4.0"/>
    <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
    <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
    <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    <add name="UrlRoutingModule-4.0" path="*" verb="*" type="System.Web.Routing.UrlRoutingModule" preCondition=""/>
  </handlers>
</system.webServer>





但是,这对我的情况没有影响。还有什么可以阻止URL路由在IIS上的Web API应用程序中工作?



However, this does not make a difference in my case. What else would prevent URL Routing from working in a Web API app on IIS?

推荐答案

是的,问题是我们有一个旧的构建脚本用于传统的ASP。 Net app,因此它没有发布Views and Areas文件夹。一旦我们在服务器上拥有所有.cshtml文件,它就可以正常工作。
Yes, the problem was that we had an old build script for a classic ASP.Net app and so it was not publishing the Views and Areas folders. Once we had all the .cshtml files on the server it worked fine.


这篇关于IIS 7.5上的Web API 2 URL路由404错误 - IIS Express正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆