Friday, February 3, 2012

More Flexible Routing For ASP.NET Web Pages

RouteTable.Routes.MapWebPageRoute("List/", "~/ListProducts.cshtml");
RouteTable.Routes.MapWebPageRoute("List/{category}/", "~/ListProducts.cshtml");
RouteTable.Routes.MapWebPageRoute("List/{category}", "~/ListProducts.cshtml", new { category = "Beverages" });
RouteTable.Routes.MapWebPageRoute("{product}/{action}", "~/Catchall.cshtml", new { product = "Beer", action = "Drink" }); 
RouteTable.Routes.MapWebPageRoute("{product}/{*action}", "~/Catchall.cshtml", new { product = "Beer", action = "Drink" }); 
RouteTable.Routes.MapWebPageRoute("List/{category}", "~/ListProducts.cshtml", constraints: new { category = "[a-zA-Z]" });

http://www.mikesdotnetting.com/Article/187/More-Flexible-Routing-For-ASP.NET-Web-Pages