[英]Web API nested resource failing under IIS8
I have a fairly straight-forward Web API project that has the following route under the Default route in WebApiConfig.cs: 我有一个相当简单的Web API项目,该Web API项目在WebApiConfig.cs中的“默认”路由下具有以下路由:
config.Routes.MapHttpRoute(
name: "ChildApi",
routeTemplate: "api/{parentController}/{parentId}/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
This works fine running under the VS2012 development server and navigating to my test URI ( /api/team/1/entries/2013-04-19
) returns the correct results. 在VS2012开发服务器下运行可以正常工作,并导航到我的测试URI( /api/team/1/entries/2013-04-19
)返回正确的结果。 Once I publish this and attempt to access the same URI using IIS8, I receive the following 404 error: 一旦发布并尝试使用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
All non-nested routes (eg /api/team/1
) work fine, but it seems that this particular route is being interpreted as a static file and IIS is attempting to serve it up as such? 所有非嵌套的路由(例如/api/team/1
)都可以正常工作,但是似乎该特定路由被解释为静态文件,而IIS试图以此作为服务吗? Has anyone else seen/resolved this problem before? 之前有没有其他人看到/解决过此问题?
Ok, so this is embarrassing... 好的,这很尴尬...
I set my route up in WebApiConfig.cs like so: 我像这样在WebApiConfig.cs中设置路由:
config.Routes.MapHttpRoute(
name: "ChildApi",
routeTemplate: "api/{parentController}/{parentId}/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
I then proceeded to add my published project to IIS under the application name "api". 然后,我继续以应用程序名称“ api”将发布的项目添加到IIS。 This (now obviously) means that the URL I should have used is /api/api/team/1/entries/2013-04-19
. 这(现在很明显)意味着我应该使用的URL是/api/api/team/1/entries/2013-04-19
。
Changing my route as follows as now resolved my issue: 如下更改我的路线即可解决我的问题:
config.Routes.MapHttpRoute(
name: "ChildApi",
routeTemplate: "{parentController}/{parentId}/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
I think the confusion was caused by the fact that this route works fine in debug mode (as if the VS2012 development server strips the first /api
from the URL). 我认为造成这种混乱的原因是,该路由在调试模式下可以正常工作(就像VS2012开发服务器从URL剥离第一个/api
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.