简体   繁体   English

Web API 2 DELETE方法始终返回500

[英]Web API 2 DELETE method always returns 500

I have a an action on my Email Web API 2 controller: 我的Email Web API 2控制器上有一个操作:

[Authorize]
[RoutePrefix("api/Email")]
public class EmailController : ApiController {

    //...

    [HttpDelete]
    [Route("Remove/{id}")]
    private void Remove(int id) {
        _repo.Remove(id);
    }
}

When I call the action from Fiddler with DELETE http://localhost:35191/api/Email/Remove/35571 (or by any other method) I get a 500 back with the generic IIS error page that gives me no information on the error. 当我使用DELETE http://localhost:35191/api/Email/Remove/35571 (或通过任何其他方法)从Fiddler调用操作时,我得到一个500返回的通用IIS错误页面,它没有提供有关错误的信息。

It seems the error is occurring before my action is ever called because setting a breakpoint within the action results in the breakpoint never being hit. 似乎错误发生在我的操作被调用之前,因为在操作中设置断点会导致断点永远不会被命中。

Is there some sort of configuration required to allow DELETE methods in IIS (Express)? 是否需要某种配置才能在IIS(Express)中使用DELETE方法?

I've tried explicitly allowing DELETE in my web.config: 我试过在我的web.config中明确允许DELETE

  <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" />

but to no avail. 但无济于事。

You have to make your exposed methods public : 你必须让你的曝光方式public

[HttpDelete]
[Route("Remove/{id}")]
public void Remove(int id) {
    _repo.Remove(id);
}

If that didn't work then you probally need to remove the WebDav(web.config): 如果这不起作用,那么您可能需要删除WebDav(web.config):

<system.webServer>
   <modules>
      <remove name="WebDAVModule" />
   </modules>
   <handlers>
      <remove name="WebDAV" />
   </handlers>
</system.webServer>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM