Esempio n. 1
0
        /// <summary>
        /// Returns relative URL for the specified tree node, using the Url Slug if the class is not in the excluded list.
        /// </summary>
        /// <param name="node">Tree node</param>
        /// <returns>The Relative Url</returns>
        protected override string GetUrlInternal(TreeNode node)
        {
            try
            {
                if (node == null)
                {
                    return(base.GetUrlInternal(node));
                }
                if (!DynamicRouteInternalHelper.UrlSlugExcludedClassNames().Contains(node.ClassName.ToLower()))
                {
                    var FoundSlug = CacheHelper.Cache(cs =>
                    {
                        if (cs.Cached)
                        {
                            cs.CacheDependency = CacheHelper.GetCacheDependency("DynamicRouting.UrlSlug|all");
                        }
                        return(UrlSlugInfoProvider.GetUrlSlugs()
                               .WhereEquals("UrlSlugNodeID", node.NodeID)
                               .WhereEquals("UrlSlugCultureCode", node.DocumentCulture)
                               .FirstOrDefault());
                    }, new CacheSettings(1440, "GetUrlSlugByNode", node.NodeID, node.DocumentCulture));

                    if (FoundSlug != null)
                    {
                        return(FoundSlug.UrlSlug);
                    }
                }
            } catch (Exception ex) {
                EventLogProvider.LogException("DynamicRouting", "DocumentUrlProvider_GetUrlInternal_Error", ex, additionalMessage: "for node " + (node == null || node.NodeGUID == null ? "null" : node.NodeGUID.ToString()));
            }
            return(base.GetUrlInternal(node));
        }
Esempio n. 2
0
        /// <summary>
        /// Returns true if a Page is found using the Dynamic Routing
        /// </summary>
        /// <param name="httpContext"></param>
        /// <param name="route"></param>
        /// <param name="parameterName"></param>
        /// <param name="values"></param>
        /// <param name="routeDirection"></param>
        /// <returns></returns>
        public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
        {
            string controllerName = values.ContainsKey("controller")
                    ? ValidationHelper.GetString(values["controller"], "")
                    : "";

            if (controllerName.Equals("KenticoFormWidget", StringComparison.InvariantCultureIgnoreCase))
            {
                return(false);
            }

            var page = DynamicRouteHelper.GetPage();

            return(page != null && !DynamicRouteInternalHelper.UrlSlugExcludedClassNames().Contains(page.ClassName.ToLower()));
        }
Esempio n. 3
0
        /// <summary>
        /// Returns presentation URL for the specified node, using UrlSlug if the class is not in the excluded list. This is the absolute URL where live presentation of given node can be found.
        /// </summary>
        /// <param name="node">Tree node to return presentation URL for.</param>
        /// <param name="preferredDomainName">A preferred domain name that should be used as the host part of the URL. Preferred domain must be assigned to the site as a domain alias otherwise site main domain is used.</param>
        /// <returns></returns>
        protected override string GetPresentationUrlInternal(TreeNode node, string preferredDomainName = null)
        {
            try
            {
                if (node == null)
                {
                    return(base.GetPresentationUrlInternal(node, preferredDomainName));
                }

                if (!DynamicRouteInternalHelper.UrlSlugExcludedClassNames().Contains(node.ClassName.ToLower()))
                {
                    var FoundSlug = CacheHelper.Cache(cs =>
                    {
                        if (cs.Cached)
                        {
                            cs.CacheDependency = CacheHelper.GetCacheDependency("DynamicRouting.UrlSlug|all");
                        }
                        return(UrlSlugInfoProvider.GetUrlSlugs()
                               .WhereEquals("UrlSlugNodeID", node.NodeID)
                               .WhereEquals("UrlSlugCultureCode", node.DocumentCulture)
                               .FirstOrDefault());
                    }, new CacheSettings(1440, "GetUrlSlugByNode", node.NodeID, node.DocumentCulture));

                    if (FoundSlug != null)
                    {
                        SiteInfo site = node.Site;
                        string   url  = FoundSlug.UrlSlug;
                        if (!string.IsNullOrEmpty(site.SitePresentationURL))
                        {
                            return(URLHelper.CombinePath(url, '/', site.SitePresentationURL, null));
                        }
                        if (!string.IsNullOrEmpty(preferredDomainName))
                        {
                            return(URLHelper.GetAbsoluteUrl(url, preferredDomainName));
                        }
                        return(URLHelper.GetAbsoluteUrl(url, site.DomainName));
                    }
                }
            } catch (Exception ex)
            {
                EventLogProvider.LogException("DynamicRouting", "DocumentUrlProvider_GetPresentationUrlInternal_Error", ex, additionalMessage: "for node " + (node == null || node.NodeGUID == null ? "null" : node.NodeGUID.ToString()));
            }

            return(base.GetPresentationUrlInternal(node, preferredDomainName));
        }
Esempio n. 4
0
        /// <summary>
        /// Returns true if a Page is found using the Dynamic Routing
        /// </summary>
        /// <param name="httpContext"></param>
        /// <param name="route"></param>
        /// <param name="parameterName"></param>
        /// <param name="values"></param>
        /// <param name="routeDirection"></param>
        /// <returns></returns>
        public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
        {
            // Never match on URL generation, this is called with the Url.Action and HtmlLink and shouldn't ever be used.
            if (routeDirection == RouteDirection.UrlGeneration)
            {
                return(false);
            }

            string controllerName = values.ContainsKey("controller")
                    ? ValidationHelper.GetString(values["controller"], "")
                    : "";

            if (controllerName.Equals("KenticoFormWidget", StringComparison.InvariantCultureIgnoreCase))
            {
                return(false);
            }

            var page = mDynamicRouteHelper.GetPage(AddPageToCacheDependency: false);

            return(page != null && !DynamicRouteInternalHelper.UrlSlugExcludedClassNames().Contains(page.ClassName.ToLower()));
        }
        /// <summary>
        /// Returns presentation URL for the specified node, using UrlSlug if the class is not in the excluded list. This is the absolute URL where live presentation of given node can be found.
        /// </summary>
        /// <param name="node">Tree node to return presentation URL for.</param>
        /// <param name="preferredDomainName">A preferred domain name that should be used as the host part of the URL. Preferred domain must be assigned to the site as a domain alias otherwise site main domain is used.</param>
        /// <returns></returns>
        protected override string GetPresentationUrlInternal(TreeNode node, string preferredDomainName = null)
        {
            if (!DynamicRouteInternalHelper.UrlSlugExcludedClassNames().Contains(node.ClassName.ToLower()))
            {
                if (node == null)
                {
                    return(null);
                }
                var FoundSlug = CacheHelper.Cache(cs =>
                {
                    if (cs.Cached)
                    {
                        cs.CacheDependency = CacheHelper.GetCacheDependency("DynamicRouting.UrlSlug|all");
                    }
                    return(UrlSlugInfoProvider.GetUrlSlugs()
                           .WhereEquals("UrlSlugNodeID", node.NodeID)
                           .WhereEquals("UrlSlugCultureCode", node.DocumentCulture)
                           .FirstOrDefault());
                }, new CacheSettings(1440, "GetUrlSlugByNode", node.NodeID, node.DocumentCulture));

                if (FoundSlug != null)
                {
                    SiteInfo site = node.Site;
                    string   url  = FoundSlug.UrlSlug;
                    if (!string.IsNullOrEmpty(site.SitePresentationURL))
                    {
                        return(URLHelper.CombinePath(url, '/', site.SitePresentationURL, null));
                    }
                    if (!string.IsNullOrEmpty(preferredDomainName))
                    {
                        return(URLHelper.GetAbsoluteUrl(url, preferredDomainName));
                    }
                    return(URLHelper.GetAbsoluteUrl(url, site.DomainName));
                }
            }

            return(base.GetPresentationUrlInternal(node, preferredDomainName));
        }
        /// <summary>
        /// Returns relative URL for the specified tree node, using the Url Slug if the class is not in the excluded list.
        /// </summary>
        /// <param name="node">Tree node</param>
        /// <returns>The Relative Url</returns>
        protected override string GetUrlInternal(TreeNode node)
        {
            if (!DynamicRouteInternalHelper.UrlSlugExcludedClassNames().Contains(node.ClassName.ToLower()))
            {
                var FoundSlug = CacheHelper.Cache(cs =>
                {
                    if (cs.Cached)
                    {
                        cs.CacheDependency = CacheHelper.GetCacheDependency("DynamicRouting.UrlSlug|all");
                    }
                    return(UrlSlugInfoProvider.GetUrlSlugs()
                           .WhereEquals("UrlSlugNodeID", node.NodeID)
                           .WhereEquals("UrlSlugCultureCode", node.DocumentCulture)
                           .FirstOrDefault());
                }, new CacheSettings(1440, "GetUrlSlugByNode", node.NodeID, node.DocumentCulture));

                if (FoundSlug != null)
                {
                    return(FoundSlug.UrlSlug);
                }
            }
            return(base.GetUrlInternal(node));
        }