I have a Web API controller, ClientController
, on which I have a method, ResetAllProgress
. I would like to map the DELETE
HTTP verb on the path api/client/progress
to this method.
I am using AttributeRouting
for this purpose because I am stuck using Web API 1. Thus I have added an attribute to my method: [DELETE("api/client/progress", ControllerPrecedence = 1)]
I have paused my application during startup and observed that a corresponding route exists in the Routes
collection. Below is a JSON serialization of the relevant parts of the IHttpRoute
object:
{
Constraints: {
inboundHttpMethod: {
AllowedMethods: ["DELETE", "OPTIONS"]
}
},
DataTokens: {
httpMethods: ["DELETE", "OPTIONS"]
}
Defaults: {
controller: ClientController,
action: ResetAllProgress
},
RouteTemplate: "/api/client/progress",
Url: "api/client/progress"
}
However, when I try to initiate a DELETE
call to api/client/progress
, I receive a 405 Method Not Allowed:
{ "Message": "The requested resource does not support http method 'DELETE'." }
If I adorn the ResetAllProgress
method with an attribute, [AcceptVerbs("DELETE")]
, then calls to api/client/*
succeed. Presumably another route mapper picks up that attribute if it is present but I want to route it specifically to api/client/progress
. I tried adding [NonAction]
to counteract this, but then the route isn't registered at all.
However, when I issue a POST
method to api/client/progress
, I get an exception:
Multiple actions were found that match the request:
System.Net.Http.HttpResponseMessage Post(MyCompany.Models.ViewModel.ClientViewModel) on type MyCompany.Api.ClientController
System.Net.Http.HttpResponseMessage ResetAllProgress() on type MyCompany.Api.ClientController
System.Net.Http.HttpResponseMessage ChangePassword(MyCompany.Models.ViewModel.ChangePasswordModel) on type MyCompany.Api.ClientController
Void SetDemo(MyCompany.Api.DemoViewModel) on type MyCompany.Api.ClientController
The other methods in that exception are not mapped to the api/client/progress
route - or shouldn't be... I'm completely out of ideas, what can I do to figure this out?