2

I am trying to send a delete request to my Web API service via Fiddler and am getting back a 405 "Method not allowed" error.

I have read extensively about removing the "WebDAV" module in web.config and similar suggestions (WebDAV is not enabled in my applicationhost.config anyway), but nothing I have tried has worked.

My service is currently running on IIS Express 10 (launching from Visual Studio). I do have this in my web.config file:

<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler"
    preCondition="integratedMode,runtimeVersionv4.0"/>

I would have thought the verb="*" piece would have allowed DELETE, but it does not seem to work.

One other note - when I inspect the response in Fiddler, under the Security heading it says: Allow: GET, POST.

I am not sure where that "Allow" parameter is being set (I am new to Web API).

Any help would be greatly appreciated. Please let me know what other information you need from me and I will add it.

Thank you!

dpberry178
  • 558
  • 6
  • 21

3 Answers3

2

You can modify the IIS Express applicationHost.config in the %userprofile%\documents\IISExpress\config folder.  To enable PUT and DELETE for extensionless Urls scroll down to the bottom of the IIS Express applicationHost.config file and look for a handler entry that starts with: <add name="ExtensionlessUrl-Integrated-4.0".... In the "verb" attribute add PUT and DELETE so the "verb" attribute looks like:  verb="GET,HEAD,POST,DEBUG,PUT,DELETE"

Mohsin Mehmood
  • 4,156
  • 2
  • 12
  • 18
2

Just reproduced this by creating a new webapi project [targeting .net framework 4.7.1]

Through Fiddler, I can hit the DELETE endpoint without any changes to web.config.

Please make sure to use correct endpoint including the id parameter.

e.g http:localhost:xxxx/api/values/id // please include the id and xxxx is port number.

If http:localhost:xxxx/api/values is used without id , I get the same result 405 Method Not Allowed

Hope this helps.

Ajeet Kumar
  • 687
  • 6
  • 12
  • Thanks for explaining this. This turned out to be the root of my issue, as I was trying to pass an object to be deleted (since the method inside my service was calling the Dapper Delete method, which accepts an object, rather than an Id). I ended up passing an Id instead then pulling the object from the db before calling the delete method and it worked fine. Dumb question - is there a way to get the DELETE verb to work when passing an object instead of an Id? – dpberry178 Mar 18 '19 at 01:55
0

Update your web config like this

<system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <modules runAllManagedModulesForAllRequests="true">
        <remove name="WebDAVModule"/> <!-- ADD THIS -->
    </modules>
Hien Nguyen
  • 24,551
  • 7
  • 52
  • 62