public class CurrentRoute : Route
{
public CurrentRoute(string url, object defaults,object constraines)
: base(url, new RouteValueDictionary(defaults), new RouteValueDictionary(constraines), new MvcRouteHandler())
{ }
public override RouteData GetRouteData(HttpContextBase httpContext)
}
{
public CurrentRoute(string url, object defaults,object constraines)
: base(url, new RouteValueDictionary(defaults), new RouteValueDictionary(constraines), new MvcRouteHandler())
{ }
public override RouteData GetRouteData(HttpContextBase httpContext)
{
RouteData routeData = base.GetRouteData(httpContext);
//过滤后,如果不满足条件,routeData为NULL.
return routeData;}
}
global.asax.cs
routes.Add(new CurrentRoute("{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
new { controller = @"News|Food|Game|Home|Test|Account" }));
最后一行的意思是只要满足条件的control才进入上面的路由.也称路由约束.
继承Route和RouteBase的区别问题还需要再学习.另Route的重写方法的作用还没有完全清楚.