public static void MapRouteLowercase(this RouteCollection routes, string name, string url, object defaults, object constraints) { if (routes == null) { throw new ArgumentNullException("routes"); } if (url == null) { throw new ArgumentNullException("url"); } var route = new LowercaseRoute(url, new MvcRouteHandler()) { Defaults = new RouteValueDictionary(defaults), Constraints = new RouteValueDictionary(constraints) }; if (String.IsNullOrEmpty(name)) { routes.Add(route); } else { routes.Add(name, route); } }
public static Route MapRouteLowerCase(this RouteCollection routes, string name, string url, object defaults, object constraints, string[] namespaces) { if (routes == null) { throw new ArgumentNullException("routes"); } if (url == null) { throw new ArgumentNullException("url"); } Route route = new LowercaseRoute(url, new MvcRouteHandler()) { Defaults = new RouteValueDictionary(defaults), Constraints = new RouteValueDictionary(constraints), DataTokens = new RouteValueDictionary() }; if ((namespaces != null) && (namespaces.Length > 0)) { route.DataTokens["Namespaces"] = namespaces; } routes.Add(name, route); return route; }
public static Route MapRouteLowercase(this RouteCollection routes, string name, string url, object defaults, object constraints) { if (routes == null) { throw new ArgumentNullException("routes"); } if (url == null) { throw new ArgumentNullException("url"); } var route = new LowercaseRoute(url, new MvcRouteHandler()) { Defaults = new RouteValueDictionary(defaults), Constraints = new RouteValueDictionary(constraints) }; if (string.IsNullOrEmpty(name)) { routes.Add(route); } else { routes.Add(name, route); } return route; }
/// <summary> /// Maps the specified URL route and sets default route values, constraints, and namespaces. Does not change casing in the /// querystring, if any. /// </summary> /// <param name="routes">A collection of routes for the application.</param> /// <param name="name">The name of the route to map.</param> /// <param name="url">The URL pattern for the route.</param> /// <param name="defaults">An object that contains default route values.</param> /// <param name="constraints">A set of expressions that specify valid values for a URL parameter.</param> /// <param name="namespaces">A set of namespaces for the application.</param> /// <returns>A reference to the mapped route.</returns> public static Route MapRouteLowercase(this RouteCollection routes, string name, string url, object defaults, object constraints, string[] namespaces) { if (routes == null) { throw new ArgumentNullException("routes"); } if (url == null) { throw new ArgumentNullException("url"); } var route = new LowercaseRoute(url, new MvcRouteHandler()) { Defaults = new RouteValueDictionary(defaults), Constraints = new RouteValueDictionary(constraints), DataTokens = new RouteValueDictionary(namespaces), }; if (namespaces != null && namespaces.Length > 0) { route.DataTokens["Namespaces"] = namespaces; } routes.Add(name, route); return(route); }
/// <summary> /// Registers the routes in the web.config file. /// </summary> /// <param name="routes">The <see cref="RouteCollection"/> to add routes to.</param> /// <param name="forceLowercase">Forces the routes to be lower case.</param> public static void RegisterRoutes(RouteCollection routes, bool forceLowercase) { RouteTableSection routesTableSection = GetRouteTableConfigurationSection(); if (routesTableSection == null || routesTableSection.Routes.Count < 1) return; for (int i = 0; i < routesTableSection.Routes.Count; i++) { RouteElement routeElement = routesTableSection.Routes[i]; Route route; if (forceLowercase) route = new LowercaseRoute( routeElement.Url, GetDefaults(routeElement), GetConstraints(routeElement), GetDataTokens(routeElement), GetInstanceOfRouteHandler(routeElement)); else route = new Route( routeElement.Url, GetDefaults(routeElement), GetConstraints(routeElement), GetDataTokens(routeElement), GetInstanceOfRouteHandler(routeElement)); routes.Add(routeElement.Name, route); } }
public static Route MapRouteLowercase(this RouteCollection routes, string name, string url, object defaults) { var route = new LowercaseRoute(url, new RouteValueDictionary(defaults), new MvcRouteHandler()); routes.Add(name, route); return(route); }
public void GetVirtualPath_WhenGivenUppercase_ReturnsLowercase() { var lowercaseRoute = new LowercaseRoute("{controller}/{action}", new MvcRouteHandler()); var routeValues = new RouteValueDictionary(new { controller = "MyTest", action = "Index" }); var path = lowercaseRoute.GetVirtualPath(requestContext, routeValues); Assert.IsNotNull(path); Assert.AreEqual("mytest/index", path.VirtualPath); }
public static Route MapRoute(this RouteCollection routes, string name, string urlPattern, params Func<string, object>[] defaultsHashes) { var defaults = new Dictionary<string, object>(); foreach (var hash in defaultsHashes) { var key = hash.Method.GetParameters()[0].Name; defaults.Add(key, hash(key)); } var route = new LowercaseRoute(urlPattern, new MvcRouteHandler()); route.Defaults = new RouteValueDictionary(defaults); route.Constraints = new RouteValueDictionary((object)null); routes.Add(name, route); return route; }
public static Route MapLowercaseRoute(this RouteCollection routes, string name, string url, object defaults, object constraints) { if (routes == null) throw new ArgumentNullException("routes"); if (url == null) throw new ArgumentNullException("url"); Route route = new LowercaseRoute(url, new MvcRouteHandler()) { Defaults = new RouteValueDictionary(defaults), Constraints = new RouteValueDictionary(constraints), DataTokens = new RouteValueDictionary(), }; routes.Add(name, route); return route; }
public static Route MapLowercaseRoute(this AreaRegistrationContext context, string name, string url, object defaults, object constraints) { if (context == null) throw new ArgumentNullException("context"); if (url == null) throw new ArgumentNullException("url"); Route route = new LowercaseRoute(url, new MvcRouteHandler()) { Defaults = new RouteValueDictionary(defaults), Constraints = new RouteValueDictionary(constraints), DataTokens = new RouteValueDictionary(), }; context.Routes.Add(route); route.DataTokens["area"] = context.AreaName; route.DataTokens["UseNamespaceFallback"] = true; return route; }
public static Route MapLowercaseRoute(this RouteCollection routes, string name, string url, object defaults, object constraints) { if (routes == null) { throw new ArgumentNullException("routes"); } if (url == null) { throw new ArgumentNullException("url"); } var route = new LowercaseRoute(url, new MvcRouteHandler()) { Defaults = new RouteValueDictionary(defaults), Constraints = new RouteValueDictionary(constraints), DataTokens = new RouteValueDictionary() }; routes.Add(name, route); return(route); }
internal static Route MapT4Route(this RouteCollection routes, string name, string url, object defaults, object constraints, string[] namespaces) { Condition.Requires(routes).IsNotNull(); Condition.Requires(url).IsNotNull(); url = RouteHelpers.UrlFormatter(url); var route = new LowercaseRoute(url, new MvcRouteHandler()) { Defaults = defaults.Convert(), Constraints = constraints.Convert(), DataTokens = new RouteValueDictionary() }; if (namespaces != null && namespaces.Length > 0) { route.DataTokens["Namespaces"] = namespaces; } routes.Add(name, route); return(route); }
/// <summary> /// Registers the routes in the web.config file. /// </summary> /// <param name="routes">The <see cref="RouteCollection"/> to add routes to.</param> /// <param name="forceLowercase">Forces the routes to be lower case.</param> public static void RegisterRoutes(RouteCollection routes, bool forceLowercase) { RouteTableSection routesTableSection = GetRouteTableConfigurationSection(); if (routesTableSection == null || routesTableSection.Routes.Count < 1) { return; } for (int i = 0; i < routesTableSection.Routes.Count; i++) { RouteElement routeElement = routesTableSection.Routes[i]; Route route; if (forceLowercase) { route = new LowercaseRoute( routeElement.Url, GetDefaults(routeElement), GetConstraints(routeElement), GetDataTokens(routeElement), GetInstanceOfRouteHandler(routeElement)); } else { route = new Route( routeElement.Url, GetDefaults(routeElement), GetConstraints(routeElement), GetDataTokens(routeElement), GetInstanceOfRouteHandler(routeElement)); } routes.Add(routeElement.Name, route); } }