Reputation: 10196
I'm trying to programmatically create a route in ASP.NET Web Api that s
config.Routes.MapHttpRoute(
name: "test",
routeTemplate: "api/foo",
defaults: new
{
controller = "Foo",
action = "Test"
},
constraints: new
{
httpMethod = new HttpMethodConstraint(HttpMethod.Get)
});
However, if I try to invoke the method with a GET I get the following response.
{
Message: "The requested resource does not support http method 'GET'."
}
If I switch the constraint to POST and invoke with a POST, all works well (and the action shows on the help page).
Any ideas what I'm doing wrong?
Upvotes: 0
Views: 1059
Reputation: 39278
Why not just use conventions and http verbs.
Ex: Define actions called Get, Post, Put etc and just hit them with the root part of the url and use http verbs to tell WEB Api which action to respond with.
Upvotes: 2