Exemplo n.º 1
0
        /// <summary>
        /// Finds the node that matches the MVC route.
        /// </summary>
        /// <param name="rootNode">The root node.</param>
        /// <param name="values">The values.</param>
        /// <param name="route">The route.</param>
        /// <returns>
        /// A controller action node represented as a <see cref="SiteMapNode"/> instance
        /// </returns>
        protected virtual ISiteMapNode FindSiteMapNodeFromMvcRoute(IDictionary <string, object> values, RouteBase route)
        {
            var routes = mvcContextFactory.GetRoutes();

            // keyTable contains every node in the SiteMap
            foreach (var node in this.keyTable.Values)
            {
                // Look at the route property
                if (!string.IsNullOrEmpty(node.Route))
                {
                    // This looks a bit weird, but if I set up a node to a general route i.e. /Controller/Action/ID
                    // I need to check that the values are the same so that it doesn't swallow all of the nodes that also use that same general route
                    if (routes[node.Route] == route && node.MatchesRoute(values))
                    {
                        return(node);
                    }
                }
                else if (node.MatchesRoute(values))
                {
                    return(node);
                }
            }

            return(null);
        }
Exemplo n.º 2
0
        protected virtual ISiteMapNode FindSiteMapNodeFromMvc(HttpContextBase httpContext)
        {
            ISiteMapNode node      = null;
            var          routes    = mvcContextFactory.GetRoutes();
            var          routeData = routes.GetRouteData(httpContext);

            if (routeData != null)
            {
                if (!routeData.Values.ContainsKey("area"))
                {
                    if (routeData.DataTokens["area"] != null)
                    {
                        routeData.Values.Add("area", routeData.DataTokens["area"]);
                    }
                    else
                    {
                        routeData.Values.Add("area", "");
                    }
                }
                if (this.RootNode != null && this.RootNode.MatchesRoute(routeData.Values))
                {
                    node = RootNode;
                }
                if (node == null)
                {
                    node = FindSiteMapNodeFromControllerAction(RootNode, routeData.Values, routeData.Route);
                }
            }
            return(node);
        }
        protected virtual RouteData FindRoutesForNode(ISiteMapNode node, string originalPath, HttpContextBase httpContext)
        {
            var routes         = mvcContextFactory.GetRoutes();
            var originalRoutes = routes.GetRouteData(httpContext);
            var nodeUrl        = node.Url;

            httpContext.RewritePath(nodeUrl, true);

            RouteData routeData = node.GetRouteData(httpContext);

            if (routeData != null)
            {
                foreach (var routeValue in node.RouteValues)
                {
                    routeData.Values[routeValue.Key] = routeValue.Value;
                }
                if (originalRoutes != null && (!routeData.Route.Equals(originalRoutes.Route) || originalPath != nodeUrl || node.Area == String.Empty))
                {
                    routeData.DataTokens.Remove("area");
                    //routeData.DataTokens.Remove("Namespaces");
                    //routeData.Values.Remove("area");
                }
            }
            return(routeData);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets the route data associated with the current node.
        /// </summary>
        /// <param name="httpContext">The HTTP context.</param>
        /// <returns>The route data associated with the current node.</returns>
        public override RouteData GetRouteData(HttpContextBase httpContext)
        {
            var       routes = mvcContextFactory.GetRoutes();
            RouteData routeData;

            if (!string.IsNullOrEmpty(this.Route))
            {
                routeData = routes[this.Route].GetRouteData(httpContext);
            }
            else
            {
                routeData = routes.GetRouteData(httpContext);
            }
            return(routeData);
        }
Exemplo n.º 5
0
        public virtual ISiteMap Create(ISiteMapBuilder siteMapBuilder, ISiteMapSettings siteMapSettings)
        {
            var routes       = mvcContextFactory.GetRoutes();
            var requestCache = mvcContextFactory.GetRequestCache();

            // IMPORTANT: We need to ensure there is one instance of controllerTypeResolver and
            // one instance of ActionMethodParameterResolver per SiteMap instance because each of
            // these classes does internal caching.
            var controllerTypeResolver        = controllerTypeResolverFactory.Create(routes);
            var actionMethodParameterResolver = actionMethodParameterResolverFactory.Create();
            var mvcResolver    = mvcResolverFactory.Create(controllerTypeResolver, actionMethodParameterResolver);
            var pluginProvider = pluginProviderFactory.Create(siteMapBuilder, mvcResolver);

            return(new RequestCacheableSiteMap(
                       pluginProvider,
                       mvcContextFactory,
                       siteMapChildStateFactory,
                       urlPath,
                       siteMapSettings,
                       requestCache));
        }