Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web API 2 DELETE method always returns 500

I have a an action on my Email Web API 2 controller:

[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.

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)?

I've tried explicitly allowing DELETE in my web.config:

  <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.

like image 882
Stephen Collins Avatar asked Oct 06 '14 16:10

Stephen Collins


1 Answers

You have to make your exposed methods 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):

<system.webServer>
   <modules>
      <remove name="WebDAVModule" />
   </modules>
   <handlers>
      <remove name="WebDAV" />
   </handlers>
</system.webServer>
like image 116
Amir Popovich Avatar answered Sep 20 '22 08:09

Amir Popovich