My WebApi.config looks like this:
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
which means it is configured to support both attribute based routing and conventional routing.
And the sample controller created:
[RoutePrefix("v1")]
public class Values1Controller : ApiController
{
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
[Route("products")]
public string Get(int id)
{
return "value";
}
}
When I invoke http://localhost.domain/api/values1/v1/ the response is value1, value2
But, when I try to invoke http://localhost.domain/api/values1/v1/products/1 (notice the products attribute route on the public string Get(int id) method, the break point is not hit.
In other words, how to call the public string Get(int id) method with the attribute routing Route(products) on top of it?