public static void MapRoute( this System.Web.Routing.RouteCollection routes, MvcRouteConfigurationSection section) { // Manipulate the Ignore List foreach (IgnoreItem ignoreItem in section.Ignore) { RouteValueDictionary ignoreConstraints = new RouteValueDictionary(); foreach (Constraint constraint in ignoreItem.Constraints) { ignoreConstraints.Add(constraint.Name, constraint.Value); } IgnoreRoute(routes, ignoreItem.Url, ignoreConstraints); } // Manipluate the Routing Table foreach (RoutingItem routingItem in section.Map) { RouteValueDictionary defaults = new RouteValueDictionary(); RouteValueDictionary constraints = new RouteValueDictionary(); if (routingItem.Controller != string.Empty) { defaults.Add("controller", routingItem.Controller); } if (routingItem.Action != string.Empty) { defaults.Add("action", routingItem.Action); } foreach (Parameter param in routingItem.Paramaters) { defaults.Add(param.Name, param.Value); if (!string.IsNullOrEmpty(param.Constraint)) { constraints.Add(param.Name, param.Constraint); } } MapRoute(routes, routingItem.Name, routingItem.Url, defaults, constraints); } }
public static void MapRoute( this System.Web.Routing.RouteCollection routes, MvcRouteConfigurationSection section ) { // Manipulate the Ignore List foreach(IgnoreItem ignoreItem in section.Ignore) { RouteValueDictionary ignoreConstraints = new RouteValueDictionary(); foreach (Constraint constraint in ignoreItem.Constraints) ignoreConstraints.Add(constraint.Name, constraint.Value); IgnoreRoute(routes, ignoreItem.Url, ignoreConstraints); } // Manipluate the Routing Table foreach (RoutingItem routingItem in section.Map) { RouteValueDictionary defaults = new RouteValueDictionary(); RouteValueDictionary constraints = new RouteValueDictionary(); if (routingItem.Controller != string.Empty) defaults.Add("controller", routingItem.Controller); if (routingItem.Action != string.Empty) defaults.Add("action", routingItem.Action); foreach (Parameter param in routingItem.Paramaters) { defaults.Add(param.Name, param.Value); if (!string.IsNullOrEmpty(param.Constraint)) { constraints.Add(param.Name, param.Constraint); } } MapRoute(routes, routingItem.Name, routingItem.Url, defaults, constraints); } }