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
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Before the AI Coding Agent Writes Code: Structuring Scattered Requirements With PARA
  • 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

Trending

  • Build a Voice Assistant With Gemini Live API
  • Member Spotlight: Shai Almong
  • Claude Code Superpowers: The 5-Tool Stack That Ends Limits and Context Amnesia
  • How to Build a Scalable SaaS Product Architecture

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  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
·
Feb. 16, 16 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
50.8K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

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

  • Before the AI Coding Agent Writes Code: Structuring Scattered Requirements With PARA
  • 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

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • 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