33

Can anyone shed any light on this? I feel like I have wasted the entire day today hunting and searching the internet for any scrap of information about how to do this. I have created a very simple WCF RESTful service. It is basically a proof of concept. I have a simple database behind it and I am just trying to get it working so that I can view, create, update and delete items. Right now I only have view and update working. I'll tackle create later. For now I can't figure out why the delete doesn't work. Almost everything I have found so far tells me that I need to disable the WebDAV module. I did that and then I got PUT to work. But I can not get DELETE to work. Whenever I attempt to call DELETE through my service I get the following error:

The remote server returned an unexpected response: (405) Method Not Allowed.

So it seems like somewhere on my server it is not allowing the DELETE verb. But for the life of me I can not figure it out. I already checked the Handler Mappings and the handler allows all verbs for the .SVC extension. I have disabled WebDAV. I'm not really sure where else to look. I am using IIS 7.5 on Windows Server 2008 R2.

(I can provide code if it would help at all)

Thanks, Corey

Corey Burnett
  • 7,048
  • 9
  • 52
  • 87

4 Answers4

69

In case anyone having the same issue.

Here is another way you can try.

in web.config

<system.webServer>
    <modules>
      <remove name="WebDAVModule" />
    </modules>
    <handlers>
      <remove name="WebDAV" /> 
    </handlers>
</system.webServer>
maxisam
  • 20,632
  • 9
  • 67
  • 77
  • 4
    Through the IIS GUI, go to **Modules** and **Handler Mappings** to remove. Thanks maxisam! – mcNux Apr 03 '13 at 16:29
  • This worked for me even though WebDAV was already configured to allow DELETE and it was also configured with Allow Verb Filtering: false. – Adam Anderson Oct 06 '14 at 20:23
  • This was all I had to do to get the PUT and DELETE methods from being 405'ed in my WCF RESTful service. Thank you. – kurt May 26 '15 at 08:47
  • 1
    check for both handlers and modules in your web.config for duplication before adding this snippet – Iman Jun 02 '17 at 14:05
  • 1
    Thanks, this worked for me. I was removing handler but not module. Once removing module deletes worked as expected. Thanks again. – Chris Cavell Jan 27 '20 at 15:51
  • I spent so much time and could not fix it until I went to iis gui and removed webdav from modules. – Bashir Momen Sep 15 '20 at 09:16
29

I just spent a ton of time trying to figure out why I kept getting 405 Method Not Allowed when using the DELETE verb. Everything I read said to uninstall WebDAV from IIS, but that seemed to break IIS in that all sites gave 503 errors. I reinstalled it, then went about looking in IIS for some setting.

It turns out that WebDAV is the problem, and it has a node on the IIS features page named "WebDAV Authoring". Clicking on that lets you then click on WebDAV Settings... to get the properties page. In the section Request Filtering Behavior, set Allow Verb Filtering to False seemed to do the trick for me (YMMV).

This seemed to be a popular result when googling for a solution, so I thought I'd add to the list of suggested solutions.

HeliNinja
  • 361
  • 3
  • 4
1

Open your website's Handler Mappings in IIS Manager

Edit each handler you want to DELETE with, clicking Request Restrictions, choosing the Verbs tab, then add DELETE to the "One of the following" list or, if appropriate within your concerns, allow all verbs.

You might need to restart your website and/or recompile your code

sirhcsivad
  • 131
  • 1
  • 7
0

Well I'm not sure if this is really an answer to my question but it did solve the problem. I simply started a new project in Visual Studio and this time I used the .NET REST Service template that I found online. Then I transferred the old code I had from my previous attempt and used it in the new project. It worked like a charm. All four verbs work correctly now (GET, PUT, POST and DELETE). So it is working now.

Corey

Corey Burnett
  • 7,048
  • 9
  • 52
  • 87