I was working with Web API for one of my new projects, and suddenly I got this error “the server responded with a status of 405 (method not allowed)” when I tried to delete a record through API. I started to scratch my head. And finally I got the solution for the same. Here I am going to share with 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.
- validation validateIntegratedModeConfiguration="false"/>
- <modules runAllManagedModulesForAllRequests="true">
- <remove name="WebDAVModule"/>
- </modules>
<handlers>
<remove name="WebDAV" />
.....
</handlers>
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.

By default the parameter here is ‘id’ as follows.
- config.Routes.MapHttpRoute(
- name: "DefaultApi",
- routeTemplate: "api/{controller}/{id}",
- defaults: new { id = RouteParameter.Optional }
- );
For Example, below is my delete function.
- // DELETE: api/Subscriber/5
- public void Delete(int subId)
- {
- tbl_Subscribers dlt = myEntity.tbl_Subscribers.Find(subId);
- if (dlt != null)
- {
- try
- {
- myEntity.tbl_Subscribers.Remove(dlt);
- myEntity.SaveChanges();
- }
- catch (Exception)
- {
- throw;
- }
- }
- }
- // DELETE: api/Subscriber/5
- public void Delete(int id)
- {
- tbl_Subscribers dlt = myEntity.tbl_Subscribers.Find(id);
- if (dlt != null)
- {
- try
- {
- myEntity.tbl_Subscribers.Remove(dlt);
- myEntity.SaveChanges();
- }
- catch (Exception)
- {
- throw;
- }
- }
- }
Conclusion
Did I miss anything that you may think is needed? Did you try Web API yet? Have you ever wanted to do this requirement? Did you find this post useful? I hope you liked this article. Please sharewith 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.
Read this article in my blog here.

Devendra loharPosted Dec 2, 2018, 12:56 AM
Yes thanks
Vishal AgnihotriPosted Jun 23, 2017, 4:29 AM
Hi Sibeesh , I also got this error “405 (method not allowed)” in POST method.I can only call API but cannot do changes in API.I have only API URL and documents for calling and get response.So please suggest me how to call successfully this.