2011-10-27 84 views
1

我的网站目前设置了以下路线路由:MVC3用一个可选的第一个参数

 routes.MapRoute(
      "BrandList", 
      "Brands", 
      new { controller = "Brand", action = "Index" } 
     ); 

     routes.MapRoute(
      "BrandProducts", 
      "{brand}/Products", 
      new { controller = "Brand", action = "Products", manufacturer = "" }, 
      new { manufacturer = new BrandConstraint() } 
     ); 
     routes.MapRoute(
      "Product", 
      "{brand}/{partNumber}", 
      new { controller = "Product", action = "Details", brand = "" }, 
      new { manufacturer = new BrandConstraint() } 
     ); 

由此产生的URL像

http://oursite/Brands      -> List of all brands 
http://oursite/SomeBrand     -> List of one brand's products 
http://oursite/SomeBrand/ProductA   -> Details for product 

我刚刚得到了指令,但是,我们现在需要提供相同的页面

http://oursite/Brands      -> List of all brands 
http://oursite/SomeBrand     -> List of one brand's products 
http://oursite/Brands/SomeBrand   -> List of one brand's products 
http://oursite/SomeBrand/ProductA   -> Details for product 
http://oursite/Brands/SomeBrand/ProductA -> Details for product 

我知道我可以创建两个路由,与当前的相同和Product路线,并在开始处增加“Brands /”。如果需要的话,我会这样做,但我更愿意不必重复每个路由条目(这不仅仅是这两个)。

任何人都有建议吗?

回答

0

您可能只想尝试使用Url重写,而不是添加指向同一位置的其他路线的复杂性。

此外,它不好有多个有效的规范格式的URL,真正的301应该是“正确的”url。

相关问题