保留的ASP.NET MVC控制器名称? [英] Reserved ASP.NET MVC Controller Names?
问题描述
所以我花了一个小时的时间调试为什么我在System.Web.Http.dll!System.Web.Http.Dispatcher.DefaultHttpControllerSelector.SelectController(System.Net.Http.HttpRequestMessage request) + 0x33f byte
上收到了客户端404和服务器端System.Web.Http.HttpResponseException
;不管我尝试了什么,我都无法获得ApiController派生类来接收请求.
So I just spent what felt like an hour debugging why I was receiving a client-side 404 and a server-side System.Web.Http.HttpResponseException
on System.Web.Http.dll!System.Web.Http.Dispatcher.DefaultHttpControllerSelector.SelectController(System.Net.Http.HttpRequestMessage request) + 0x33f byte
; no matter what I tried I could not get my ApiController derivative to receive requests.
最后,在尝试将其转换为常规的Controller
无效后,我想到将名称从APIController
更改为APIXController
只是为了使所有工作正常.
In the end, after trying to convert it to a regular Controller
to no effect, it occurred to me to change the name from APIController
to APIXController
only to have everything work.
- 在哪里说明
API
是保留的控制器名称? - 保留的控制器名称的完整列表在哪里?
- 是否可以绕过使用
APIController
作为我的班级名称的限制,如果是这样,我该如何去做?
- Where is it stated that
API
is a reserved controller name? - Where is the full list of reserved controller names?
- Is it possible to bypass this restriction on using
APIController
as my class name, and if so, how do I go about doing so?
我检查的第一件事是我的路由配置,这是沼泽标准
One of the first things I checked was my route configuration, which is the bog standard
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
推荐答案
APIController不是保留名称.但是,如果您使用的是标准MVC4模板,则默认情况下它包含WebAPI堆栈的实例,并且此实例会注册以/api
APIController is not a reserved name. But, if you're using a standard MVC4 template, then by default it includes an instance of a WebAPI stack, and this registers a route that starts with /api
您最有可能遇到这种情况.
You were most likely running into that.
在AppStart下和WebApiConfig.cs文件中查找.
Look under AppStart and in the WebApiConfig.cs file.
顺便说一句,关键的调试症状是WebApi使用的System.Web.Http中的任何内容,并且不会在MVC应用程序中显示.
By the way, the key debugging symptom is anything in System.Web.Http, that is used by WebApi, and would not show up in an MVC app.
这篇关于保留的ASP.NET MVC控制器名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!