标签:
App_Start文件夹中的RouteConfig
MapRoute( string name, string url);
MapRoute( string name, string url, object defaults);
MapRoute( string name, string url, string[] namespaces);
MapRoute( string name, string url, object defaults, object constraints); MapRoute( string name, string url, object defaults, string[] namespaces);
MapRoute( string name, string url, object defaults, object constraints, string[] namespaces);
routes.MapRoute(
name: "Default2",
url: "{controller}-{action}-{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
constraints: new {
controller = @"\d{4}",
httpMethod = new HttpMethodConstraint("GET") }
);
// 酒店列表页匹配
routes.MapRoute(
"酒店列表页",
"hotels/{action}-{city}-{price}-{star}",
new { controller = "Hotel", action = "list", city = "beijing", price = "-1,-1", star = "-1" },
new { city = @"[a-zA-Z]*", price = @"(\d)+\,(\d)+", star = "[-1-5]" }
);
// 酒店频道所有匹配
routes.MapRoute(
"酒店首页",
"hotels/{*iiii}",
new { controller = "Hotel", action = "default", hotelid = "" }
);
// 网站首页默认匹配
routes.MapRoute(
"网站首页",
"{*values}",
new { controller = "Home", action = "index" }
);
标签:
原文地址:http://www.cnblogs.com/weloveshare/p/5314055.html