DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Iptables Basic Commands for Novice
  • DataWeave Interview Question: Compare IDs From Two Arrays and Create a New Array
  • Step-by-Step Guide to Use Anypoint MQ: Part 4
  • Why Your Test Automation Is Always Behind the Code And the Architecture That Fixes It

Trending

  • Building an Image Classification Pipeline With Apache Camel and Deep Java Library (DJL)
  • Building a Skill-Based Agentic Reviewer with Claude Code: A Practical Guide Using Skills.MD, MCP Servers, Tools, and Tasks
  • A Deep Dive into Tracing Agentic Workflows (Part 1)
  • A Scalable Framework for Enterprise Salesforce Optimization: Turning Outcomes Into an Operating System
  1. DZone
  2. Culture and Methodologies
  3. Agile
  4. How to Solve "The Server Responded With a Status of 405 (Method Not Allowed)"

How to Solve "The Server Responded With a Status of 405 (Method Not Allowed)"

I was working with Web API for one of my new projects, when suddenly I got this error message: "the server responded with a status of 405 (method not allowed)" when I tried to delete a record through API. I began to scratch my head, and finally, I came up with a solution.

By 
Sibeesh Venu user avatar
Sibeesh Venu
·
Feb. 16, 16 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
50.7K Views

Join the DZone community and get the full member experience.

Join For Free

i was working with web api for one of my new projects, when suddenly i got this error message: "the server responded with a status of 405 (method not allowed)" when i tried to delete a record through api. i began to scratch my head, and finally, i came up with a solution. here, i am going to share with you that solution. i hope you will like this.

following are the various 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.

<validation validateintegratedmodeconfiguration="false"/>
    <modules runallmanagedmodulesforallrequests="true">
        <remove name="webdavmodule"/>
    </modules>

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


<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.

image title

webapi config file

by default, the parameter here is ‘id’ as follows.


config.routes.maphttproute(
                name: "defaultapi",
                routetemplate: "api/{controller}/{id}",
                defaults: new { id = routeparameter.optional }
            );

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.


 // 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;
                }
            }
        }

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.


// 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;
                }
            }
        }

it works fine after i have changed the parameter name. i hope you find it helpful. that is all. we did it. 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 with me your valuable suggestions and feedback.

Web API Filter (software) Coding (social sciences) Requirement POST (HTTP) Record (computer science) Scratch (programming language)

Published at DZone with permission of Sibeesh Venu. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Iptables Basic Commands for Novice
  • DataWeave Interview Question: Compare IDs From Two Arrays and Create a New Array
  • Step-by-Step Guide to Use Anypoint MQ: Part 4
  • Why Your Test Automation Is Always Behind the Code And the Architecture That Fixes It

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook