1

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?

Alex
  • 7,639
  • 3
  • 45
  • 58
  • 2
    Have you decorated the method with the [HttpDelete] attribute? – Mike Schwartz Jan 14 '16 at 17:44
  • Have you tried [this](http://stackoverflow.com/questions/10906411/asp-net-web-api-put-delete-verbs-not-allowed-iis-8)? – Yuval Itzchakov Jan 14 '16 at 17:52
  • @MikeSchwartz thank you for the suggestion, however this has the same effect as `[AcceptVerbs("DELETE")]` - that is to say, it registers the Delete method for `api/client` – Alex Jan 15 '16 at 10:34
  • @YuvalItzchakov I don't think it's a server issue with accepting the Delete method - after all, if I use the attribute in my previous comment the site can accept it... Just for the wrong route! – Alex Jan 15 '16 at 10:36
  • I "fixed" my issue by replacing the `DELETE` attribute with a `POST` to `api/client/deleteprogress`... pragmatic at best – Alex Jan 15 '16 at 11:17

0 Answers0