Solutions for the error “the server responded with a status of 405 (method not allowed)”

WebApi Config File

[toc]

Introduction

I was working with Web API for one of my new project, suddenly I got this error “the server responded with a status of 405 (method not allowed)” when I try to delete a record through API. I have started to scratch my head. And finally I got the solution for the same. Here I am going to share you that solution. I hope you will like this.

Following are the solutions that you can try out if you get this error.

Solution 1: Changing Web.Config file

This is the first thing you must try. Please add the below tags in the Web.Config file under modules .

If you are getting the error still, try adding one tag under handlers as follows.

If the above didn’t work for you, you can go to the next solution.

Solution 2: Revert back the parameter name

As you all know we have a file called WebApiConfig.cs where we set the MapHttpRoute and other config filters.

WebApi Config File
WebApi Config File

By default the parameter here is ‘id’ as follows.

Now if you changed the parameter of your function in any case, you need to revert it back to ‘id’, or you need to make changes in the WebApiConfig.cs file.

For Example, below is my delete function.

As you can see I have changed my parameter to ‘subId’. Because of this I was getting the error “the server responded with a status of 405 (method not allowed)” always. Then I changed my function as follows.

It works fine after I have changed the parameter name. I hope you find it helpful. That is all. We did it. Have a happy coding.

Conclusion

Did I miss anything that you may think which is needed? Did you try Web API yet? Have you ever wanted to do this requirement? Could you find this post as useful? I hope you liked this article. Please share me your valuable suggestions and feedback.

Your turn. What do you think?

A blog isn’t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, Asp.Net Forum instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I can.

Kindest Regards
Sibeesh Venu

Leave a Reply

Your email address will not be published. Required fields are marked *

Serverless 360