如何停止的ASP.NET Web API PUT动词返回500 [英] How do I stop ASP.NET web api PUT verb returning 500
问题描述
我运行在IIS 7.5的ASP.NET Web API应用程序。当我尝试使用PUT动词访问什么,我得到一个500错误。
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防爆preSS相同code,我得到我期待的回应。
When I run the same code using IIS Express on my local machine I get the response I am expecting.
值得关注的是我得到了 405没有找到方法
反应,所以我在IIS中删除的模块的WebDav参考。
Worth noting that I was getting the 405 Method not found
response, so I removed WebDav reference in Modules in IIS.
我使用的Visual Studio中为您提供了控制器当你第一次创建项目:
I'm using the controller that Visual Studio gives you when you first create the project:
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)
{
}
}
(一对夫妇的变化)。当我运行POST / GET操作,我得到的答复我希望,但放一不工作。
(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.
推荐答案
请参阅this计算器问题
基本上默认ExtensionlessUrlHandler不接受PUT和DELETE动词。只需要添加他们在web.config
Basically the default ExtensionlessUrlHandler does not accept PUT and DELETE verb. Just need to add them in the 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>
这篇关于如何停止的ASP.NET Web API PUT动词返回500的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!