Represents a URL route registered with lower case.
Inheritance: System.Web.Routing.Route
Esempio n. 1
0
        private static void MapRoute(string name, string url, 
            IDictionary<string, object> defaults, IDictionary<string, object> constraints, ICollection<string> namespaces)
        {
            if (url == null)
                throw new ArgumentNullException("url");
            if (constraints == null)
                throw new ArgumentNullException("constraints");

            LowerCaseRoute route = new LowerCaseRoute(url, new MvcRouteHandler())
            {
                Name = name,
                Defaults = new RouteValueDictionary(defaults),
                Constraints = new RouteValueDictionary(constraints)
            };

            if ((namespaces != null) && (namespaces.Count > 0))
            {
                route.DataTokens = new RouteValueDictionary();
                route.DataTokens["Namespaces"] = namespaces;
            }

            var existingRoute = RouteTable.Routes[name];
            if (existingRoute != null)
                RouteTable.Routes.Remove(existingRoute);

            RouteTable.Routes.Add(name, route);
        }
        /// <summary>
        /// Maps a route, ensuring characters are registered in lower case.
        /// </summary>
        /// <param name="routes">The target <see cref="RouteCollection"/>.</param>
        /// <param name="name">The name of the route.</param>
        /// <param name="url">The route URL pattern.</param>
        /// <param name="defaults">The route default values.</param>
        /// <param name="constraints">The route parameter constraints.</param>
        /// <param name="namespaces">The route namespaces.</param>
        /// <exception cref="ArgumentNullException"><paramref name="routes"/> or <paramref name="url"/> is <c>null</c></exception>
        public static void MapRouteLowercase(this RouteCollection routes, string name, string url, IDictionary<string, object> defaults, IDictionary<string, 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())
            {
                Name = name,
                Defaults = defaults == null ? null : new RouteValueDictionary(defaults),
                Constraints = constraints == null ? null : new RouteValueDictionary(constraints),
                DataTokens = new RouteValueDictionary(),
            };

            if ((namespaces != null) && (namespaces.Length > 0))
            {
                route.DataTokens["Namespaces"] = namespaces;
            }

            if (string.IsNullOrEmpty(name))
            {
                routes.Add(route);
            }
            else
            {
                for (var i = 0; i < routes.Count; i++)
                {
                    var r = routes[i] as LowerCaseRoute;
                    if (r != null && r.Name == name)
                    {
                        log.WarnFormat("Overwriting an identically named route ('{0}') for url '{1}' and controller '{2}' with a new route for url '{3}' and controller '{4}'",
                            name, r.Url, r.Defaults["controller"], route.Url, route.Defaults["controller"]);

                        routes[i] = route;
                        return;
                    }
                }

                routes.Add(name, route);
            }
        }