【发布时间】:2014-10-04 21:47:52
【问题描述】:
我有两条路线:
routes.MapRoute(
name: "Default1",
url: "{controller}/{action}/{id}/{id2}"
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
我的控制器看起来像:
public class ProductsController : ApiController
{
...
public int GetAll(int id,int id2)
{
return 1;
}
public Product GetProduct(int id)
{
....
return item;
}
}
当我写信时:http://localhost:9000/api/products/2
它匹配第二条规则并且:
但是当我写http://localhost:9000/api/products/2/3(假设符合第一条规则)时:
问题
我的错误在哪里?
nb:
运行http://localhost:9000/api/products/2?id2=1 确实给出了正确的结果 - 但是,嘿!我专门为这个做了一个路线!
【问题讨论】:
标签: asp.net asp.net-web-api routing