How to allow a DELETE method with IIS Express and Web API?

2.1k Views Asked by At

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!

3

There are 3 best solutions below

2
On BEST ANSWER

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.

0
On

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"

0
On

Update your web config like this

<system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <modules runAllManagedModulesForAllRequests="true">
        <remove name="WebDAVModule"/> <!-- ADD THIS -->
    </modules>