Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7655179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:26:49+00:00 2026-05-31T12:26:49+00:00

I am having difficulty getting the DELETE Method on my Controller to fire when

  • 0

I am having difficulty getting the DELETE Method on my Controller to fire when submitting the request over ASP.NET Web API. It returns a 404 but I cannot figure out why. The GET & POST requests work as expected, returning both a list of items as well as a single item when provided an id, but when I call the API using a DELETE request I get a 404 ERROR.

Scenario:

1. ASP.NET Web Forms application …

Not an MVC application although I have installed the MVC4 package in order to leverage the Web API features.

2. Route Table definition in global.asax

            RouteTable.Routes.MapHttpRoute(

                    "Default", 
                    "api/{controller}/{id}", 
                    new { id = RouteParameter.Optional } 
            );

3. Controller definition

    public HttpResponseMessage<Customer> Post(Customer customer)
    {
        CustomerDb.Customers.AddObject(customer);
        CustomerDb.SaveChanges();
        var response = new HttpResponseMessage<Customer>(customer, HttpStatusCode.Created);
        response.Headers.Location = new Uri(Request.RequestUri, "/api/Customer/"+customer.id.ToString());
        return response;
    }

    public CustomerDTO Get(int id)
    {
        CustomerDTO custDTO = null;
        Customer cust = CustomerDb.Customers.Where(c => c.id == id).SingleOrDefault();
        if (cust == null)
            throw new HttpResponseException(HttpStatusCode.BadRequest);
        else
            custDTO = new CustomerDTO(cust);
        return custDTO;
    }

    public IEnumerable<CustomerDTO> Get()
    {
        IQueryable<Customer> custs = CustomerDb.Customers.AsQueryable();

        List<CustomerDTO> dto = new List<CustomerDTO>();
        foreach (Customer cust in custs)
        {
            dto.Add(new CustomerDTO(cust));
        }

        return dto;
    }

    public Customer Delete(int id)
    {
        Customer cust = CustomerDb.Customers.Where(c => c.id == id).SingleOrDefault();
        if (cust == null)
            throw new HttpResponseException(HttpStatusCode.BadRequest);

        CustomerDb.Customers.DeleteObject(cust);
        CustomerDb.SaveChanges();
        return (cust);
    }

I have some of the methods throwing a BadRequest error instead of a 404 when a customer cannot be found so I don’t get these responses confused with the REAL problem. Obviously in a real implementation a no customer would return a 404 error.

4. Ajax Call via JQuery to delete item.

function deleteCustomer(id) {

        var apiUrl = "/api/customer/{0}";
        apiUrl = apiUrl.replace("{0}", id);

        $.ajax({
            url: apiUrl,
            type: 'DELETE',
            cache: false,
            statusCode: {
                200: function (data) {
                }, // Successful DELETE
                404: function (data) {
                    alert(apiUrl + " ... Not Found");
                }, // 404 Not Found
                400: function (data) {
                    alert("Bad Request O");
                } // 400 Bad Request
            } // statusCode
        }); // ajax call
    };

SO I am expecting that the singel route map should accomodate ALL the scenarios …

  1. GET api/customer — Returns ALL customers
  2. GET api/customer/5 — Returns the customer whose ID = 5
  3. POST api/customer — Creates a new customer record
  4. DELETE api/customer/5 — Deletes the customer whose ID = 5

1,2 & 3 work without a problem, just the DELET does not work. I have tried MANY iterations and different tweaks, to no avail. I still feel however that I am overlooking something small. I feel like the problem must be around theRoute mapping but I don’t see why this route would not succesfully handle the DELETE request.

Any help would be greatly appreciated.

Thank You!

Gary

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T12:26:50+00:00Added an answer on May 31, 2026 at 12:26 pm

    Do you have this defined in your web.config?

       <system.webServer>
              <modules runAllManagedModulesForAllRequests="true">
              </modules>
        </system.webServer>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having difficulty getting a rspec test for a controller to pass. I
I'm having difficulty getting the binding to fire off on a user control that
I'm having difficulty getting widgets in a QDialog resized automatically when the dialog itself
I'm having difficulty getting XQuery to work. I downloaded Saxon-HE 9.2. It seems to
I'm having great difficulty getting my Android application to play videos from the SD
I'm having an extremely difficulty time getting the flowplayer to show up and the
I'm having a lot of difficulty getting strophe's 'attach()' function working. I am working
I'm having difficulty getting my footer image in Internet Explorer 8 to display on
I've been having difficulty getting anything more than a simple index / to return
I am having difficulty getting my page to show up correctly at various browser

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.