[英]Web API nested resource failing under IIS8
我有一个相当简单的Web API项目,该Web API项目在WebApiConfig.cs中的“默认”路由下具有以下路由:
config.Routes.MapHttpRoute(
name: "ChildApi",
routeTemplate: "api/{parentController}/{parentId}/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
在VS2012开发服务器下运行可以正常工作,并导航到我的测试URI( /api/team/1/entries/2013-04-19
)返回正确的结果。 一旦发布并尝试使用IIS8访问相同的URI,我将收到以下404错误:
HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
Most likely causes:
The directory or file specified does not exist on the Web server.
The URL contains a typographical error.
A custom filter or module, such as URLScan, restricts access to the file.
Things you can try:
Create the content on the Web server.
Review the browser URL.
Create a tracing rule to track failed requests for this HTTP status code and see which module is calling SetStatus. For more information about creating a tracing rule for failed requests, click here.
Detailed Error Information:
Module IIS Web Core
Notification MapRequestHandler
Handler StaticFile
Error Code 0x80070002
所有非嵌套的路由(例如/api/team/1
)都可以正常工作,但是似乎该特定路由被解释为静态文件,而IIS试图以此作为服务吗? 之前有没有其他人看到/解决过此问题?
好的,这很尴尬...
我像这样在WebApiConfig.cs中设置路由:
config.Routes.MapHttpRoute(
name: "ChildApi",
routeTemplate: "api/{parentController}/{parentId}/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
然后,我继续以应用程序名称“ api”将发布的项目添加到IIS。 这(现在很明显)意味着我应该使用的URL是/api/api/team/1/entries/2013-04-19
。
如下更改我的路线即可解决我的问题:
config.Routes.MapHttpRoute(
name: "ChildApi",
routeTemplate: "{parentController}/{parentId}/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
我认为造成这种混乱的原因是,该路由在调试模式下可以正常工作(就像VS2012开发服务器从URL剥离第一个/api
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.