2016-12-14 35 views
1

在ASP.NET Web Pages项目(而不是Web窗体,而不是MVC)中,我正在使用Mike Brind的 More Flexible Routing For ASP.NET Web Pages在使用MapWebPageRoute映射路由时使用通配符

我想创建挑选UPS任意数量的路径要素,但在一个特定的单词结尾的途径,例如:

  • mydomain.com/route1/word
  • mydomain.com/route1/route2 /字
  • mydomain.com/route1/route2/route3/word
  • ...等等等等

我试图用通配符映射的路线,但在第在没有工作,如:

RouteTable.Routes.Ignore("{*routes}/word");

有没有办法来映射这些航线possibilites或我必须为每一个possibiility一个途径,例如:

  • RouteTable.Routes.MapWebPageRoute("{route1}/word", "~/mypage.cshtml");
  • RouteTable.Routes.MapWebPageRoute("{route1}/{route2}/word", "~/mypage.cshtml");
  • RouteTable.Routes.MapWebPageRoute("{route1}/{route2}/{route3}/word", "~/mypage.cshtml");
  • ...等等等等

回答

1

我最终想出了一个解决方案。

RouteTable.Routes.MapWebPageRoute("{*routes}", 
    "~/mypage.cshtml", 
    constraints: new { routes = @".*(/word)" }); 

所以使用约束就是答案。