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...
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.