public string GetRouteDescriptorKey(HttpContextBase httpContext, RouteBase routeBase) {
            var route = routeBase as Route;
            var dataTokens = new RouteValueDictionary();

            if (route != null) {
                dataTokens = route.DataTokens;
            }
            else {
            var routeData = routeBase.GetRouteData(httpContext);

                if (routeData != null) {
                    dataTokens = routeData.DataTokens;
                }
            }

            var keyBuilder = new StringBuilder();

            if (route != null) {
                keyBuilder.AppendFormat("url={0};", route.Url);
            }

            // the data tokens are used in case the same url is used by several features, like *{path} (Rewrite Rules and Home Page Provider)
            if (dataTokens != null) {
                foreach (var key in dataTokens.Keys) {
                    keyBuilder.AppendFormat("{0}={1};", key, dataTokens[key]);
                }
            }

            return keyBuilder.ToString().ToLowerInvariant();
        }
Example #2
0
 public RedirectRoute(RouteBase sourceRoute, RouteBase targetRoute, bool permanent, RouteValueDictionary additionalRouteValues)
 {
     SourceRoute = sourceRoute;
     TargetRoute = targetRoute;
     Permanent = permanent;
     AdditionalRouteValues = additionalRouteValues;
 }
 /// <summary>
 /// Creates the ambiguous controller exception.
 /// </summary>
 /// <param name="route">The route.</param>
 /// <param name="controllerName">Name of the controller.</param>
 /// <param name="matchingTypes">The matching types.</param>
 /// <returns></returns>
 internal static InvalidOperationException CreateAmbiguousControllerException(RouteBase route, string controllerName, ICollection<Type> matchingTypes)
 {
     StringBuilder stringBuilder = new StringBuilder();
     foreach (Type current in matchingTypes)
     {
         stringBuilder.AppendLine();
         stringBuilder.Append(current.FullName);
     }
     Route route2 = route as Route;
     string message;
     if (route2 != null)
     {
         message = string.Format(CultureInfo.CurrentUICulture,
                                 "The request for '{0}' has found the following matching controllers:{2}\r\n\r\nMultiple types were found that match the controller named '{0}'. This can happen if the route that services this request does not specify namespaces to search for a controller that matches the request. If this is the case, register this route by calling an overload of the 'MapRoute' method that takes a 'namespaces' parameter.",
                                 new object[]
                                 {
                                     controllerName,
                                     route2.Url,
                                     stringBuilder
                                 });
     }
     else
     {
         message = string.Format(CultureInfo.CurrentUICulture,
                                 "The request for '{0}' has found the following matching controllers:{2}\r\n\r\nMultiple types were found that match the controller named '{0}'.",
                                 new object[]
                                 {
                                     controllerName,
                                     stringBuilder
                                 });
     }
     return new InvalidOperationException(message);
 }
 public RouteData(RouteBase route, IRouteHandler routeHandler)
 {
     this._values      = new RouteValueDictionary();
     this._dataTokens  = new RouteValueDictionary();
     this.Route        = route;
     this.RouteHandler = routeHandler;
 }
        internal static InvalidOperationException CreateAmbiguousControllerException(RouteBase route, string controllerName, ICollection<Type> matchingTypes)
        {
            // we need to generate an exception containing all the controller types
            StringBuilder typeList = new StringBuilder();
            foreach (Type matchedType in matchingTypes)
            {
                typeList.AppendLine();
                typeList.Append(matchedType.FullName);
            }

            string errorText;
            Route castRoute = route as Route;
            if (castRoute != null)
            {
                errorText = String.Format(CultureInfo.CurrentCulture, MvcResources.DefaultControllerFactory_ControllerNameAmbiguous_WithRouteUrl,
                                          controllerName, castRoute.Url, typeList);
            }
            else
            {
                errorText = String.Format(CultureInfo.CurrentCulture, MvcResources.DefaultControllerFactory_ControllerNameAmbiguous_WithoutRouteUrl,
                                          controllerName, typeList);
            }

            return new InvalidOperationException(errorText);
        }
 public RouteData(RouteBase route, IRouteHandler routeHandler)
 {
     this._values = new RouteValueDictionary();
     this._dataTokens = new RouteValueDictionary();
     this.Route = route;
     this.RouteHandler = routeHandler;
 }
        // Copied ALMOST verbatim from DefaultControllerFactory, modified as necessary to avoid dependency on the ASP.NET hosted infrastructure
        private Type GetControllerTypeWithinNamespaces(RouteBase route, string controllerName, HashSet<string> namespaces)
        {
            // Once the master list of controllers has been created we can quickly index into it
            // GKM - Not available... ControllerTypeCache.EnsureInitialized(BuildManager);

            ICollection<Type> matchingTypes = ControllerTypeCache.GetControllerTypes(controllerName, namespaces);
            switch (matchingTypes.Count)
            {
                case 0:
                    // no matching types 
                    return null;

                case 1:
                    // single matching type
                    return matchingTypes.First();

                default:
                    // multiple matching types 
                    throw new Exception(
                        string.Format("Ambiguous controller match for for controller '{0}' in namespaces '{1}'.", 
                                      controllerName, string.Join(", ", namespaces.ToArray())));

                    // GKM: Internal --> throw CreateAmbiguousControllerException(route, controllerName, matchingTypes);
            }
        } 
		public VirtualPathData (RouteBase route, string virtualPath)
		{
			// arguments can be null.
			Route = route;
			VirtualPath = virtualPath;
			DataTokens = new RouteValueDictionary ();
		}
 public RedirectRoute(RouteBase sourceRoute, RouteBase targetRoute, bool permanent, Func<RequestContext, RouteValueDictionary> additionalRouteValues)
 {
     SourceRoute = sourceRoute;
     TargetRoute = targetRoute;
     Permanent = permanent;
     AdditionalRouteValuesFunc = additionalRouteValues;
 }
 public VirtualPathData(RouteBase route, string virtualPath)
 {
     // arguments can be null.
     Route       = route;
     VirtualPath = virtualPath;
     DataTokens  = new RouteValueDictionary();
 }
Example #11
0
		public RouteData (RouteBase route, IRouteHandler routeHandler)
		{
			// arguments can be null.
			Route = route;
			RouteHandler = routeHandler;

			DataTokens = new RouteValueDictionary ();
			Values = new RouteValueDictionary ();
		}
 private string GetAreaToken(RouteBase routeBase)
 {
     var route = routeBase as Route;
     if (route == null || route.DataTokens == null)
     {
         return null;
     }
     return route.DataTokens["area"] as string;
 }
        public RouteData(RouteBase route, IRouteHandler routeHandler)
        {
            // arguments can be null.
            Route        = route;
            RouteHandler = routeHandler;

            DataTokens = new RouteValueDictionary();
            Values     = new RouteValueDictionary();
        }
		public NormalizeRoute(RouteBase route, bool requireLowerCase, bool appendTrailingSlash)
			: base(route)
		{
			if (route == null) {
				throw new ArgumentNullException("route");
			}
			AppendTrailingSlash = appendTrailingSlash;
			RequireLowerCase = requireLowerCase;
		}
Example #15
0
        public ShellRoute(RouteBase route, ShellSettings shellSettings, IWorkContextAccessor workContextAccessor, IRunningShellTable runningShellTable) {
            _route = route;
            _shellSettings = shellSettings;
            _runningShellTable = runningShellTable;
            _workContextAccessor = workContextAccessor;
            if (!string.IsNullOrEmpty(_shellSettings.RequestUrlPrefix))
                _urlPrefix = new UrlPrefix(_shellSettings.RequestUrlPrefix);

            Area = route.GetAreaName();
        }
Example #16
0
 static string BuildRoute(RouteBase routeBase)
 {
     var route = ((Route)routeBase);
     var allowedMethods = ((HttpMethodConstraint)route.Constraints["httpMethod"]).AllowedMethods;
     return string.Format("{0} {1} => {2}#{3}",
                          DisplayAllowedMethods(allowedMethods),
                          string.IsNullOrEmpty(route.Url) ? "/" : route.Url,
                          route.Defaults["controller"],
                          route.Defaults["action"]);
 }
 public NormalizeRoute(RouteBase route, bool requireLowerCase, bool appendTrailingSlash)
 {
     if (route == null)
     {
         throw new ArgumentNullException("route");
     }
     this.InternalRoute = route;
     this.AppendTrailingSlash = appendTrailingSlash;
     this.RequireLowerCase = requireLowerCase;
 }
 protected virtual string GetAreaName(RouteBase route) {
     var area = route as IRouteWithArea;
     if(area != null) {
         return area.Area;
     }
     var route2 = route as Route;
     if((route2 != null) && (route2.DataTokens != null)) {
         return (route2.DataTokens["area"] as string);
     }
     return null;
 }
        public ShellRoute(RouteBase route, ShellSettings shellSettings, IWorkContextAccessor workContextAccessor, IRunningShellTable runningShellTable, Func<IDictionary<string, object>, Task> pipeline) {
            _route = route;
            _shellSettings = shellSettings;
            _runningShellTable = runningShellTable;
            _pipeline = pipeline;
            _workContextAccessor = workContextAccessor;
            if (!string.IsNullOrEmpty(_shellSettings.RequestUrlPrefix))
                _urlPrefix = new UrlPrefix(_shellSettings.RequestUrlPrefix);

            Area = route.GetAreaName();
        }
Example #20
0
        public static void RegisterRoutes(RouteCollection routes, ref RouteBase signalRHubRoute)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            signalRHubRoute = routes.MapHubs();

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }
		public static string findRouteName(RouteBase _Route, IDictionary<string, RouteBase> _RouteNames, bool remove = true)
		{
			string _Result = "";
			foreach (KeyValuePair<string, RouteBase> _RoutePair in _RouteNames) {
				if (_RoutePair.Value == _Route) {
					_Result = _RoutePair.Key;
					_RouteNames.Remove(_RoutePair);
					break;
				}
			}
			return _Result;
		}
        public static RouteData Create(RouteBase route_routeBase, IRouteHandler routeHandler_iRouteHandler)
        {
            RouteData routeData = new RouteData(route_routeBase, routeHandler_iRouteHandler)
            ;

            return(routeData);

            // TODO: Edit factory method of RouteData
            // This method should be able to configure the object in all possible ways.
            // Add as many parameters as needed,
            // and assign their values to each field by using the API.
        }
		internal static string GetURL(RouteBase route, RequestContext context, IResource resource)
		{
			var location = resource.Location;

			var values = new RouteValueDictionary();

			if (location is TypeLocation)
			{
				TypeLocation tl = location as TypeLocation;
				values.Add("assembly", tl.ProxyType.Assembly.GetName().Name);
				values.Add("name", tl.ProxyType.FullName);
			}
			else if (location is EmbeddedLocation)
			{
				EmbeddedLocation el = location as EmbeddedLocation;
				values.Add("assembly", el.Assembly.GetName().Name);
				values.Add("name", el.ResourceName);
			}
			else if (location is VirtualPathLocation)
			{
				VirtualPathLocation vl = location as VirtualPathLocation;
				if (!(resource is IProxyResource))
					return UrlHelper.GenerateContentUrl(vl.VirtualPath, context.HttpContext);
				var p = vl.VirtualPath;
				if (p[0] == '/') p = p.Substring(1);
				values.Add("name", p);
			}
			else if (location is ExternalLocation)
			{
				ExternalLocation el = location as ExternalLocation;
				return el.Uri.ToString();
			}
			else
				throw new Exception("Unknown IResourceLocationType");
			
			var pr = resource as IProxyResource;
			if (pr != null && (pr.CultureSensitive || pr.CultureUISensitive))
			{
				if (pr.CultureSensitive)
					values.Add("culture", CultureInfo.CurrentCulture.LCID.ToString("x"));
				if (pr.CultureUISensitive)
					values.Add("cultureUI", CultureInfo.CurrentUICulture.LCID.ToString("x"));
			}

			values.Add("version", ToHex(resource.Version));

			var virtualPath = route.GetVirtualPath(context, values);
			if (virtualPath == null) throw new Exception("Routing is incomplete.");

			var url = UrlHelper.GenerateContentUrl("~/" + virtualPath.VirtualPath, context.HttpContext);
			return url;
		}
Example #24
0
        public static string GetAreaName(RouteBase route) {
            IRouteWithArea routeWithArea = route as IRouteWithArea;
            if (routeWithArea != null) {
                return routeWithArea.Area;
            }

            Route castRoute = route as Route;
            if (castRoute != null && castRoute.DataTokens != null) {
                return castRoute.DataTokens["area"] as string;
            }

            return null;
        }
Example #25
0
 public RedirectRoute(
     RouteBase sourceRoute,
     RouteBase targetRoute,
     bool permanent,
     RouteValueDictionary additionalRouteValues,
     Action<RequestContext, RedirectRoute> onRedirectAction)
 {
     SourceRoute = sourceRoute;
     TargetRoute = targetRoute;
     Permanent = permanent;
     AdditionalRouteValues = additionalRouteValues;
     OnRedirectAction = onRedirectAction;
 }
Example #26
0
		protected virtual void ReOrderRoutingTable(RouteCollection areaRoutes) {
			var existingRoutes = new RouteBase[RouteTable.Routes.Count];
			RouteTable.Routes.CopyTo(existingRoutes, 0);

			var aggregateList = new List<RouteBase>();
			aggregateList.AddRange(areaRoutes);
			aggregateList.AddRange(existingRoutes);

			RouteTable.Routes.Clear();

			foreach (var route in aggregateList) {
				RouteTable.Routes.Add(route);
			}
		}
Example #27
0
 // Methods
 public static string GetAreaName(RouteBase route)
 {
     IRouteWithArea area = route as IRouteWithArea;
     if (area != null)
     {
         return area.Area;
     }
     Route route2 = route as Route;
     if ((route2 != null) && (route2.DataTokens != null))
     {
         return (route2.DataTokens["area"] as string);
     }
     return null;
 }
 public static string GetAreaName(RouteBase route)
 {
     // get area name from all the route including registered custom routes
     var area = route as IRouteWithArea;
     if (area != null)
     {
         return area.Area;
     }
     var route2 = route as Route;
     if ((route2 != null) && (route2.DataTokens != null))
     {
         return (route2.DataTokens["area"] as string);
     }
     return null;
 }
Example #29
0
 public static string GetAreaName(RouteBase route)
 {
     IRouteWithArea routeWithArea = route as IRouteWithArea;
     if (routeWithArea != null)
     {
         return routeWithArea.Area;
     }
     else
     {
         Route routeTmp = route as Route;
         if (routeTmp != null && routeTmp.DataTokens != null)
             return routeTmp.DataTokens["area"] as string;
         else
             return (string)null;
     }
 }
		private static RouteData CreateRouteData(RouteBase route, RouteValueDictionary routeValues, RouteValueDictionary dataTokens)
		{
			RouteData routeData = new RouteData();

			foreach (KeyValuePair<string, object> kvp in routeValues)
			{
				routeData.Values.Add(kvp.Key, kvp.Value);
			}

			foreach (KeyValuePair<string, object> kvp in dataTokens)
			{
				routeData.DataTokens.Add(kvp.Key, kvp.Value);
			}

			routeData.Route = route;
			routeData.DataTokens["ParentActionViewContext"] = new ViewContext();
			return routeData;
		}
Example #31
0
        public ShellRoute(RouteBase route, ShellSettings shellSettings, ILifetimeScope shellLifetimeScope, IRunningShellTable runningShellTable)
        {
            _route = route;
            _shellSettings = shellSettings;
            _runningShellTable = runningShellTable;
            _container = new LifetimeScopeContainer(shellLifetimeScope);
            if (!string.IsNullOrEmpty(_shellSettings.RequestUrlPrefix))
                _urlPrefix = new UrlPrefix(_shellSettings.RequestUrlPrefix);

            var routeWithArea = route as IRouteWithArea;
            if (routeWithArea != null) {
                Area = routeWithArea.Area;
            }

            var routeWithDataTokens = route as Route;
            if ((routeWithDataTokens != null) && (routeWithDataTokens.DataTokens != null)) {
                Area = (routeWithDataTokens.DataTokens["area"] as string);
            }
        }
		/// <summary>
		/// Check whether the specified route should be exposed in the JavaScript output
		/// </summary>
		/// <param name="routeBase">Route to check</param>
		/// <returns><c>false</c> if the route should definitely be blocked, <c>true</c> if the route should be exposed (or unsure)</returns>
		public bool AllowRoute(RouteBase routeBase)
		{
			var route = routeBase as Route;
			if (route == null)
				return true;

			// WebForms - Not supported
			if (route.RouteHandler is PageRouteHandler)
				return false;

			// Ignore routes
			if (route.RouteHandler is StopRoutingHandler)
				return false;

			// ASP.NET WebAPI (https://github.com/Daniel15/RouteJs/issues/9)
			// Ugly hack so we don't have to reference the WebAPI assembly for now.
			if (route.GetType().FullName == "System.Web.Http.WebHost.Routing.HttpWebRoute")
				return false;

			return true;
		}
        public RedirectRoute To(RouteBase targetRoute, Func<RequestContext, RouteValueDictionary> routeValues)
        {
            if (targetRoute == null)
            {
                throw new ArgumentNullException("targetRoute");
            }

            // Set once only
            if (TargetRoute != null)
            {
                throw new InvalidOperationException(/* TODO */);
            }
            TargetRoute = targetRoute;

            // Set once only
            if (AdditionalRouteValuesFunc != null)
            {
                throw new InvalidOperationException(/* TODO */);
            }
            AdditionalRouteValuesFunc = routeValues;
            return this;
        }
        private static string Name(RouteBase original)
        {
            if (RouteTable.Routes.Contains(original))
            {
                var field = typeof(RouteCollection).GetField("_namedMap", BindingFlags.NonPublic | BindingFlags.Instance);
                if (field == null)
                {
                    return null;
                }

                var value = field.GetValue(RouteTable.Routes) as Dictionary<string, RouteBase>;
                if (value == null)
                {
                    return null;
                }

                var query = from pair in value where pair.Value == original select pair.Key;
                return query.SingleOrDefault();
            }

            return string.Empty;
        }
Example #35
0
 public VirtualPathData(RouteBase route, string virtualPath)
 {
     this.Route       = route;
     this.VirtualPath = virtualPath;
 }
Example #36
0
 public VirtualPathData(RouteBase route, string virtualPath)
 {
 }
 public RouteData(RouteBase route, IRouteHandler routeHandler)
 {
 }
        public void WrapsMvcRouteBaseDerivedTypes(RoutesInspector sut, System.Web.Routing.IRouteHandler routeHandler, IInspectorContext context, NewRouteBase route, RouteBase newRoute)
        {
            RouteTable.Routes.Clear();
            RouteTable.Routes.Add("Test", route);

            context.ProxyFactory.Setup(x => x.IsWrapClassEligible(typeof(RouteBase))).Returns(true);
            context.ProxyFactory.Setup(x => x.WrapClass((RouteBase)route, It.IsAny <IEnumerable <IAlternateMethod> >(), It.IsAny <object[]>())).Returns(newRoute).Verifiable();

            sut.Setup(context);

            context.ProxyFactory.VerifyAll();
            Assert.Same(newRoute, RouteTable.Routes[0]);
        }
Example #39
0
 public VirtualPathData(RouteBase route, string virtualPath)
 {
     Route       = route;
     VirtualPath = virtualPath;
 }
Example #40
0
        private RouteModel GetRouteModelForRoute(ITabContext context, MvcRouteBase routeBase,
                                                 Dictionary <int, List <RouteDataMessage> > routeMessages,
                                                 Dictionary <int, Dictionary <int, List <ProcessConstraintMessage> > > constraintMessages)
        {
            RouteModel routeModel = new RouteModel();

            RouteDataMessage routeMessage = SafeFirstOrDefault(routeMessages.GetValueOrDefault(routeBase.GetHashCode()));

            if (routeMessage != null)
            {
                routeModel.Duration = routeMessage.Duration;
                routeModel.IsMatch  = routeMessage.IsMatch;
            }

            MvcRoute route = routeBase as MvcRoute;

            if (route != null)
            {
                routeModel.Area = (route.DataTokens != null && route.DataTokens.ContainsKey("area"))
                                        ? route.DataTokens["area"].ToString() : null;
                routeModel.Url = route.Url;

                // Append localizations if possible
                LocalizationCollectionRoute localizationCollectionRoute = null;
                FieldInfo fieldInfo = route.GetType().GetField("__target");

                if (fieldInfo != null)
                {
                    localizationCollectionRoute = fieldInfo.GetValue(route) as LocalizationCollectionRoute;
                }

                if (localizationCollectionRoute != null)
                {
                    routeModel.Url += " (LocalizationRoute)";
                    routeModel.Url += Environment.NewLine;

                    foreach (LocalizationRoute localizationRoute in
                             localizationCollectionRoute.LocalizedRoutes.OrderBy(x => x.Culture))
                    {
                        routeModel.Url += string.Format(Environment.NewLine + "{0} ({1})", localizationRoute.Url(),
                                                        !string.IsNullOrEmpty(localizationRoute.Culture) ? localizationRoute.Culture : "neutral");
                    }

                    if (!localizationCollectionRoute.LocalizedRoutes.Any())
                    {
                        routeModel.Url += Environment.NewLine + "! No translations exists - this route will not be accessible !";
                    }
                }

                routeModel.RouteData   = ProcessRouteData(route.Defaults, routeMessage);
                routeModel.Constraints = ProcessConstraints(context, route, constraintMessages);
                routeModel.DataTokens  = ProcessDataTokens(route.DataTokens);
            }
            else
            {
                routeModel.Url = routeBase.ToString();
            }

            IRouteNameMixin routeName = routeBase as IRouteNameMixin;

            if (routeName != null)
            {
                routeModel.Name = routeName.Name;
            }

            return(routeModel);
        }
Example #41
0
 public RouteData(RouteBase route, IRouteHandler routeHandler)
 {
     Route        = route;
     RouteHandler = routeHandler;
 }