2016-12-14 33 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)" }); 

所以使用約束就是答案。