ASP.NET Web Api:请求的资源不支持 http 方法“GET" [英] ASP.NET Web Api: The requested resource does not support http method 'GET'

查看:64
本文介绍了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'.

为什么这不再起作用了?

Why doesn't this work anymore?

(我想我可以去掉 {action} 并制作大量控制器,但这感觉很混乱.)

(I suppose I could get rid of {action} and just make a ton of controllers, but that feels messy.)

推荐答案

如果你没有在控制器中为你的 action 配置任何 HttpMethod,那么在 RC 中它被假定为只有 HttpPost.在 Beta 中,假定支持所有方法 - GET、PUT、POST 和 Delete.这是从 beta 到 RC 的一个小变化.您可以使用 [AcceptVerbs("GET", "POST")] 轻松地为您的操作装饰多个 httpmethod.

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")].

这篇关于ASP.NET Web Api:请求的资源不支持 http 方法“GET"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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