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

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

How are you handling the data revolution? We want your take on what's real, what's hype, and what's next in the world of data engineering.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

SBOMs are essential to circumventing software supply chain attacks, and they provide visibility into various software components.

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

  • The Shift to Open Industrial IoT Architectures With Data Streaming
  • Reducing Hallucinations Using Prompt Engineering and RAG
  • Vibe Coding: Conversational Software Development — Part 1 Introduction
  • One Checkbox to Cloud: Migrating from Tosca DEX Agents to E2G
  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.4K 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

Partner Resources

×

Comments

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

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • 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
  • [email protected]

Let's be friends: