请求的资源不支持的HTTP方法和QUOT;放" [英] Requested resource does not support http method "PUT"

查看:944
本文介绍了请求的资源不支持的HTTP方法和QUOT;放"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用AttributeRouting与我的Web API(MVC 4)。

I'm using AttributeRouting with my Web API (MVC 4).

为什么这项工作?

    [AcceptVerbs("PUT")]
    [PUT("api/v1/tokens/current")]
    public MemoryToken UpdateToken([FromBody] DeviceTokenViewModel viewModel)
    {...}

而这其中不?

    [PUT("api/v1/tokens/current")]
    public MemoryToken UpdateToken([FromBody] DeviceTokenViewModel viewModel)
    {...}

错误消息:所请求的资源不支持HTTP方法PUT。
为什么我必须明确地接受PUT动词?

Error message: The requested resource does not support http method "PUT". Why do I have to explicitly accept the PUT verb?

我只是困惑,因为用POST类似的工作就好了(我没有指定接受的动词):

I'm just confused because something similar with POST works just fine (I don't have to specify the accepted verbs):

 [POST("api/v1/tokens")]
 public MemoryToken CreateToken()
 {...}

从各个岗位我相信这与我在web.config中的设置做。该网站的服务器部分目前看起来是这样的:

From various other posts I believe it has to do with the setting in my web.config. The web server section currently looks like this:

<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true" />
<handlers>
  <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
  <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
  <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
  <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
  <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
  <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
  <add name="AttributeRouting" path="routes.axd" verb="*" type="AttributeRouting.Web.Logging.LogRoutesHandler, AttributeRouting.Web" />
</handlers>

我试过几件事情像删除WebDAV和东西。但是毫无效果,到目前为止(除非明确允许注解的PUT动词)。

I tried a couple things like removing WebDav and stuff. But nothing worked so far (unless explicitly allowing the PUT verb in the annotation).

呵呵,我使用内置的开发服务器视觉工作室。

Oh, I am using Visual Studios built-in development server.

谢谢你们!

推荐答案

在此<一个href=\"http://www.asp.net/web-api/overview/web-api-routing-and-actions/routing-and-action-selection\">link他们所描述的POST方法是默认的,如果没有的行动相匹配。所以这就是为什么它仍然适用于您的CreateToken()方法没有HttpPost属性。

In this link they describe the POST method as being the default if none of the actions match. So that's why it still works for your CreateToken() method without an HttpPost attribute .


  • 您可以用一个属性指定HTTP方法:AcceptVerbs,HttpDelete,HTTPGET,HttpHead,HttpOptions,HttpPatch,HttpPost或HttpPut

  • 否则,如果控制器方法的名称开头获取,邮报,放,删除,头,选项,或补丁,然后按约定行动支持HTTP方法。

  • 如果没有上述情况,方法支持POST。

  • You can specify the HTTP method with an attribute: AcceptVerbs, HttpDelete, HttpGet, HttpHead, HttpOptions, HttpPatch, HttpPost, or HttpPut.
  • Otherwise, if the name of the controller method starts with "Get", "Post", "Put", "Delete", "Head", "Options", or "Patch", then by convention the action supports that HTTP method.
  • If none of the above, the method supports POST.

这篇关于请求的资源不支持的HTTP方法和QUOT;放&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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