的ASP.NET Web API:请求的资源不支持HTTP方法“GET”
我有上ApiController以下动作:
I've got the following action on an ApiController:
public string Something()
{
return "value";
}
和我如下配置我的路线:
And I've configured my routes as follows:
routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
在测试版,这工作得很好,但我只更新到最新的候选发布版,现在我看到像这样的调用错误:
In the beta, this worked just fine, but I just updated to the latest Release Candidate and now I'm seeing errors on calls like this:
所请求的资源不支持HTTP方法GET。
The requested resource does not support http method 'GET'.
为什么不这项工作了?
(我想我可以摆脱{}行动,只是做一吨的控制器,但感觉凌乱。)
(I suppose I could get rid of {action} and just make a ton of controllers, but that feels messy.)
如果您还没有配置任何列举HTTPMethod在控制器的动作,这被认为是唯一HttpPost在RC。在测试中,假定支持所有方法 - GET,PUT,POST和DELETE。这是测试版的小变化RC。你可以很容易德科雷一个以上列举HTTPMethod与的[AcceptVerbs(GET,POST)]你的行动。
If you have not configured any HttpMethod on your action in controller, it is assumed to be only HttpPost in RC. In Beta, it is assumed to support all methods - GET, PUT, POST and Delete. This is a small change from beta to RC. You could easily decore more than one httpmethod on your action with [AcceptVerbs("GET", "POST")].