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
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modern Digital Website Security: Prepare to face any form of malicious web activity and enable your sites to optimally serve your customers.

Containers Trend Report: Explore the current state of containers, containerization strategies, and modernizing architecture.

Low-Code Development: Learn the concepts of low code, features + use cases for professional devs, and the low-code implementation process.

E-Commerce Development Essentials: Considering starting or working on an e-commerce business? Learn how to create a backend that scales.

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
  • Improving ui-select Control

Trending

  • Reading an HTML File, Parsing It and Converting It to a PDF File With the Pdfbox Library
  • Scaling SRE Teams
  • Chopping the Monolith in a Smarter Way
  • Elevating React Development: Unleashing the Power of ChatGPT for React Developers
  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.

Sibeesh Venu user avatar by
Sibeesh Venu
·
Feb. 16, 16 · Tutorial
Like (3)
Save
Tweet
Share
49.9K 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, DZone MVB. 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
  • Improving ui-select Control

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

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 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: