No action was found on the controller ApiController

Viewed 2387

For my API, I want to be able to handle scenarios where the call is made using an incorrect URL (i.e. URL that does not match any controller or action.)

For this I have implemented routing so that it matches any route:

config.Routes.MapHttpRoute(
    name: "CatchAll",
    routeTemplate: "{*any}",
    defaults: new { controller = "Error", action = "Handler" }
);

And I have implemented the controller - action as follows:

[Route("api/v1/Handler")]
[ActionName("Handler")]
public HttpResponseMessage Get() {...}

When I give an incorrect URL, I get the message:

No action was found on the controller 'Error' that matches the name 'Handler'

Not sure where the mistake is.

1 Answers
Related