Web API 2 DELETE method always returns 500

I have 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 an action from Fiddler using DELETE http://localhost:35191/api/Email/Remove/35571 (or any other method), I get back 500 with a common IIS error page that does not give me any error information.

It seems like an error occurs before my action has ever been called, because setting a breakpoint in the action causes the breakpoint to never hit.

Is there some kind of configuration needed to use DELETE methods in IIS (Express)?

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

+5
source share
1 answer

You must make your public methods public :

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

If this does not work, you probably need to remove WebDav (web.config):

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

Source: https://habr.com/ru/post/1204120/


All Articles