using System.Web.Mvc; using System.Web.Routing; namespace KingT.Web.TimeLine { public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( name: "TimeLine", url: "tl/{visitId}/{from}/{to}", defaults: new { controller = "Home", action = "Index", from = UrlParameter.Optional, to = UrlParameter.Optional } ); //如果能匹配到这一个就不再向下匹配 routes.MapRoute( name: "TimeLineSetting", url: "setting", defaults: new { controller = "Home", action = "Setting" } ); routes.MapRoute( name: "TimeLineSettingItem", url: "setting/{item}", defaults: new { controller = "Home", action = "SettingItem" } ); routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); } } }
http://localhost:8099/tl/2015122800143/2015-12-24/2016-1-28 可以匹配第一个、
routes.MapRoute( name: "TimeLine", url: "{controller}/{action}/tl/{visitId}/{from}/{to}", defaults: new { controller = "Home", action = "Index", from = UrlParameter.Optional, to = UrlParameter.Optional } );
http://localhost:8099/Home/Index/tl/2015122800143/2015-12-24/2016-1-28 可以匹配上面的路由