Here is my routing configuration:
config.Routes.MapHttpRoute(
name: "ActionApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
And, here is my controller:
public class ProductsController : ApiController
{
[AcceptVerbs("Get")]
public object GetProducts()
{
// return all products...
}
[AcceptVerbs("Get")]
public object Product(string name)
{
// return the Product with the given name...
}
}
When I try api/Products/GetProducts/, it works. api/Products/Product?name=test also works, but api/Products/Product/test does not work. What am I doing wrong?
UPDATE:
Here's what I get when I try api/Products/Product/test:
{
"Message": "No HTTP resource was found that matches the request URI 'http://localhost:42676/api/Products/Product/test'.",
"MessageDetail": "No action was found on the controller 'Products' that matches the request."
}