0

I've got a controller set up and working for all of my GET requests, but when it comes to the PUT requests my Web Site (not a Web App, if that makes any difference) is returning a 405.

I've got the route defined in my Global.asax Application_Start() with the other routes, and it's the first one, so it should be evaluated first (if my understanding is correct):

void Application_Start(object sender, EventArgs e)
{
    System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls
            | System.Net.SecurityProtocolType.Tls11
            | System.Net.SecurityProtocolType.Tls12;

    RouteTable.Routes.MapHttpRoute("FilteredSpecialOrders",
        routeTemplate: "api/sales/filteredRequests",
        defaults: new { controller = "Sales", action = "filteredRequests" });

    // subsequent routes are here
}

My SalesController has a method with the right attributes for type of request (Put) and the action name that matches my routeTemplate, as well as the [FromBody] attribute on the parameter:

[HttpPut, ActionName("filteredRequests")]
public IHttpActionResult PutSpecialOrders([FromBody] RequestFilter filter)
{ 
    // do the needful
}

...and my client side code creates the body of the message (filter) as a JavaScript object and sends the .put requests via axios:

getFilteredRequests: async function () {
    let filter = {
        name: this.name,
         age: this.yearsOld,
        /* other name/value pairs of course */
    };

    const response = await axios.put(salesApi + 'filteredRequests', filter);
    let data = response.data;
    return data;
}

...but I'm always getting back a 405 - Method Not Allowed. What am I forgetting? I'm not sure how the JSON object that gets sent in the body is serialized into my RequestFilter object - does that happen automagically or do I need to define that somewhere? I've made sure that the names are the same on both ends, but other than that...

Scott Baker
  • 10,013
  • 17
  • 56
  • 102
  • Check your IIS `web.config`, you likely have WebDAV still enabled, which inserts itself before application code to handle `PUT` requests. – Dai Oct 20 '21 at 17:23
  • what am I looking for specifically? `WebDAV` or some other value? Because there's nothing about WebDAV in there. – Scott Baker Oct 20 '21 at 17:28
  • https://stackoverflow.com/questions/6147181/405-method-not-allowed-in-iis7-5-for-put-method – Dai Oct 20 '21 at 17:32
  • If you'll post your comment as an answer I'll accept it. – Scott Baker Oct 20 '21 at 17:48

1 Answers1

0

I edited my web.config to remove the WebDAV bits per this post - but I also had to switch my pipeline from classic mode to integrated to get it to work.

Scott Baker
  • 10,013
  • 17
  • 56
  • 102