13

I already worked with web API and had a lot of problems like posting multiple parameters. I upgraded to WebApi2 to use routing attributes and now have problems like:

"message":"The requested resource does not support http method 'DELETE'."

I spent all day searching Stack Overflow and the web to solve the problem:

  • Removed webdav
  • In http protocol allow all get,put,post,delete
  • Added the [HTTPDelete] attribute
  • Added name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0"
  • Searched Google for the necessary help here

Can someone please guide me on this?

5
  • Your title needs be more descriptive Commented Dec 7, 2013 at 19:37
  • The problem with giving us a search query (in number 5) is, are we meant to believe that you've accessed all 1 million results that that query returns (at least for me, today)? If not, how does it help us to help you? Commented Dec 8, 2013 at 6:12
  • I tried four items mentioned above from search result Commented Dec 8, 2013 at 7:29
  • So no answer? Amazing, out of nothing comes a big issue Commented Aug 11, 2014 at 15:05
  • Possible duplicate of When setting a form's opacity should I use a decimal or double? Commented Sep 7, 2016 at 11:14

3 Answers 3

25

I had the same problem. Adding the below code to your web.config should fix the problem under the system.webserver section:

<system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <modules runAllManagedModulesForAllRequests="true">
        <remove name="WebDAVModule"/>
Sign up to request clarification or add additional context in comments.

2 Comments

--> didi it for me: <remove name="WebDAVModule"/>
Worked for me too, was very odd because the issue occured after the app was working fine on the dev server for weeks. An unrelated update to a different page somehow caused this error, but this fixed it!
11

I had the same problem, because my controller was like this:

[HttpDelete]
public HttpResponseMessage Delete(string Id)
{
     ....
}

And on the client I used the send the ID as request body:

var url = '/api/upload';
var data = JSON.stringify({ 'Id': id }); // <-- In the body
$.ajax({
    url: url,
    type: 'DELETE',
    data: data, // <-- in the body
    contentType: 'application/json'
})

When I changed the client to use it as URL parameter instead it worked:

var url = '/api/upload/' + id; // <- In the URL
$.ajax({
    url: url,
    type: 'DELETE',
    contentType: 'application/json'
});

2 Comments

I think you need all that its in the above answer plus make the request correctly
this is the answer
4

The JavaScript code for the DELETE verb must be like this:

$.ajax({
    **url: "/api/SomeController/" + id,**
    type: "DELETE",
    dataType: "json",
    success: function(data, statusText) {
        alert(data);
    },
    error: function(request, textStatus, error) {
        alert(error);
        debugger;
    }
});

Do NOT use something like this,

...
data: {id:id}
...

as when you are using the POST method.

1 Comment

Pavel Kharibin, you saved my day. Thanks for answere

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.