I'm running an ASP.NET Web API application on IIS 7.5. When I try to access anything using the PUT verb, I get a 500 error.
我在IIS 7.5上运行ASP.NET Web API应用程序。当我尝试使用PUT动词访问任何内容时,我收到500错误。
When I run the same code using IIS Express on my local machine I get the response I am expecting.
当我在本地计算机上使用IIS Express运行相同的代码时,我得到了我期待的响应。
Worth noting that I was getting the 405 Method not found
response, so I removed WebDav reference in Modules in IIS.
值得注意的是我得到了405 Method not found响应,所以我删除了IIS中的模块中的WebDav引用。
I'm using the controller that Visual Studio gives you when you first create the project:
我正在使用Visual Studio在您第一次创建项目时为您提供的控制器:
public class ValuesController : ApiController
{
// GET api/values
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
// GET api/values/5
public string Get(int id)
{
return "value";
}
// POST api/values
public HttpResponseMessage Post()
{
return Request.CreateResponse(HttpStatusCode.Ambiguous);
}
// PUT api/values/5
[System.Web.Http.AcceptVerbs("PUT")]
public HttpResponseMessage Put()
{
return Request.CreateResponse(HttpStatusCode.SeeOther);
}
// DELETE api/values/5
public void Delete(int id)
{
}
}
(with a couple of changes). When I run the POST/GET actions, I get the responses I expect but the PUT one isn't working.
(有一些变化)。当我运行POST / GET操作时,我得到了我期望的响应但是PUT没有工作。
1 个解决方案
#1
1
See this * question
请参阅此*问题
Basically the default ExtensionlessUrlHandler does not accept PUT and DELETE verb. Just need to add them in the web.config
基本上默认的ExtensionlessUrlHandler不接受PUT和DELETE动词。只需要在web.config中添加它们
<system.webServer>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE" type="System.Web.Handlers.TransferRequestHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
#1
1
See this * question
请参阅此*问题
Basically the default ExtensionlessUrlHandler does not accept PUT and DELETE verb. Just need to add them in the web.config
基本上默认的ExtensionlessUrlHandler不接受PUT和DELETE动词。只需要在web.config中添加它们
<system.webServer>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE" type="System.Web.Handlers.TransferRequestHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>