我有一个Web API项目,但无法启用其"PUT/Patch"请求。
Fiddler返回的响应是:
HTTP/1.1 405 Method Not Allowed
Cache-Control: no-cache
Pragma: no-cache
Allow: GET,POST,DELETE
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/8.0
X-AspNet-Version: 4.0.30319
X-SourceFiles: =?UTF-8?B?QzpcUHJvamVjdHNcZG90TmV0XFdlYkFQSVxBZFNlcnZpY2VcQWRTZXJ2aWNlXGFwaVxpbXByZXNzaW9uXDE1?=
X-Powered-By: ASP.NET
Date: Tue, 06 May 2014 14:10:35 GMT
Content-Length: 72
{"message":"The requested resource does not support http method 'PUT'."}
根据上述回复,“PUT”动词不被接受。但是我无法找出相关的处理程序在哪里配置。该类的“Put”方法声明如下:
[HttpPatch]
[HttpPut]
public HttpResponseMessage Put(Int32 aID, [FromBody] ImpressionModel impressionModel)
{
bla, bla, bla, bla
}
我已阅读并实施了以下线程中解释的更改:
- Asp.NET Web API - 405 - HTTP verb used to access this page is not allowed - how to set handler mappings
- http://www.asp.net/web-api/overview/testing-and-debugging/troubleshooting-http-405-errors-after-publishing-web-api-applications
尽管我已经注释掉了ApplicationsHost.config文件中的所有 “Handlers”,但仍然无法使用“PUT”命令对我的Web API项目进行操作,仍然收到405响应。
我使用VS2012 Premium和IIS Express(我假设它是版本8)。我还尝试了VS Dev Server,但也得到了相同的结果。
我已经没有任何想法了。感谢您的帮助。
谢谢Lee