コード例 #1
0
        /// <summary>
        /// This method is used to get all Url Elements in one go
        /// </summary>
        /// <param name="pageID">The ID of the page you are interested in</param>
        /// <param name="cacheDuration">The length of time these values should be cached once retrieved</param>
        /// <param name="_isPlaceHolder">Is this url a place holder (Not a real url)</param>
        /// <param name="_tabLink">Is this Url a link to an external site/resource</param>
        /// <param name="_urlKeywords">Are there any keywords that should be added to this url</param>
        /// <param name="_pageName">Does this url have a friendly page name other than the default</param>
        public static UrlElements GetUrlElements(int pageID, double cacheDuration)
        {
            UrlElements urlElements = new UrlElements();

            // pageID 0 is a default page shared across portals with no real settings
            if (pageID == 0)
            {
                return(urlElements);
            }

            string urlElementsCacheKey = UrlElementsCacheKey(pageID);

            // calling HttpContext.Current.Cache all the time incurs a small performance hit so get a reference to it once and reuse that for greater performance
            Cache applicationCache = HttpContext.Current.Cache;

            // if any values are null refetch
            if (applicationCache[urlElementsCacheKey] == null)
            {
                using (SqlConnection conn = new SqlConnection(SiteConnectionString))
                {
                    try
                    {
                        // Open the connection
                        conn.Open();

                        using (SqlCommand cmd = new SqlCommand(GetUrlElementsQuery, conn))
                        {
                            var parameterPageId = new SqlParameter("@PageID", SqlDbType.Int, 4)
                            {
                                Value = pageID
                            };
                            cmd.Parameters.Add(parameterPageId);

                            SqlDataReader pageElements = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                            if (pageElements.HasRows)
                            {
                                pageElements.Read();

                                urlElements.PageName = Convert.ToString(pageElements["PageSEOName"]);
                                if (!String.IsNullOrEmpty(urlElements.PageName))
                                {
                                    urlElements.PageName = CleanNoAlphanumerics(urlElements.PageName);
                                }

                                urlElements.PageTitle = Convert.ToString(pageElements["PageTitle"]);
                                if (!String.IsNullOrEmpty(urlElements.PageTitle))
                                {
                                    urlElements.PageTitle = CleanNoAlphanumerics(urlElements.PageTitle);
                                }

                                urlElements.UrlKeywords = Convert.ToString(pageElements["Keywords"]);
                                if (!String.IsNullOrEmpty(urlElements.UrlKeywords))
                                {
                                    urlElements.UrlKeywords = CleanNoAlphanumerics(urlElements.UrlKeywords);
                                }

                                urlElements.TabLink = Convert.ToString(pageElements["ExternalLink"]);

                                if (pageElements["IsPlaceHolder"].ToString() != String.Empty)
                                {
                                    urlElements.IsPlaceHolder = bool.Parse(pageElements["IsPlaceHolder"].ToString());
                                }
                                // insert value in cache so it doesn't always try to retrieve it

                                // NOTE: This is the tabsettings Cache Dependency approach see note above
                                // applicationCache.Insert(isPlaceHolderKey, _isPlaceHolder.ToString(), new CacheDependency(null, dependencyKey));
                                if (cacheDuration == 0)
                                {
                                    applicationCache.Insert(urlElementsCacheKey, urlElements);
                                }
                                else
                                {
                                    applicationCache.Insert(urlElementsCacheKey, urlElements, null, DateTime.Now.AddMinutes(cacheDuration), Cache.NoSlidingExpiration);
                                }
                            }
                            // close the reader
                            pageElements.Close();
                        }
                    }
                    catch
                    {
                        // TODO: Decide whether or not this should be logged. If it is a large site upgrading then it would quickly fill up a log file.
                        // If there is no value in the database then it thows an error as it is expecting something.
                        // This can happen with the initial setup or if no entries for a tab have been made
                    }

                    finally
                    {
                        // Close the connection
                        if (conn != null)
                        {
                            conn.Close();
                        }
                    }
                }
            }
            else
            {
                urlElements = (UrlElements)applicationCache[urlElementsCacheKey];
            }
            return(urlElements);
        }
コード例 #2
0
        /// <summary>
        /// Takes a Tab ID and builds the url for get the desidered page (non default)
        /// containing the application path, portal alias, tab ID, and language.
        /// </summary>
        /// <param name="targetPage">Linked page</param>
        /// <param name="pageID">ID of the page</param>
        /// <param name="modID">ID of the module</param>
        /// <param name="culture">Client culture</param>
        /// <param name="customAttributes">Any custom attribute that can be needed. Use the following format...single attribute: paramname--paramvalue . Multiple attributes: paramname--paramvalue/paramname2--paramvalue2/paramname3--paramvalue3 </param>
        /// <param name="currentAlias">Current Alias</param>
        /// <param name="urlKeywords">Add some keywords to uniquely identify this tab. Usual source is UrlKeyword from TabSettings.</param>
        public override string BuildUrl(string targetPage, int pageID, int modID, CultureInfo culture,
                                        string customAttributes, string currentAlias, string urlKeywords)
        {
            // Get Url Elements this helper method (Will either retrieve from cache or database)
            UrlElements urlElements = UrlBuilderHelper.GetUrlElements(pageID, _cacheMinutes);

            //2_aug_2004 Cory Isakson
            //Begin Navigation Enhancements
            if (!(targetPage.ToLower().EndsWith(_ignoreTargetPage.ToLower())))
            // Do not modify URLs when working with TabLayout Administration Page
            {
                // if it is a placeholder it is not supposed to have any url
                if (urlElements.IsPlaceHolder)
                {
                    return(string.Empty);
                }

                // if it is a tab link it means it is a link to an external resource
                if (urlElements.TabLink.Length != 0)
                {
                    return(urlElements.TabLink);
                }
            }
            //End Navigation Enhancements
            StringBuilder sb = new StringBuilder();

            // Obtain ApplicationPath
            if (targetPage.StartsWith("~/"))
            {
                sb.Append(UrlBuilderHelper.ApplicationPath);
                targetPage = targetPage.Substring(2);
            }
            sb.Append("/");

            //if (!targetPage.EndsWith(".aspx")) //Images
            //{
            //    sb.Append(targetPage);
            //    return sb.ToString();
            //}

            HttpContext.Current.Trace.Warn("Target Page = " + targetPage);

            // Separate path
            // If page contains path, or it is not an aspx
            // or handlerFlag is not set: do not use handler
            if (!targetPage.Equals(HttpUrlBuilder.DefaultPage) && !targetPage.Equals("DesktopDefault.aspx"))
            {
                sb.Append(targetPage);
                // if !!targetPage.EndsWith(".aspx") it's an image. Return
                if (!targetPage.EndsWith(".aspx"))
                {
                    return(sb.ToString());
                }
                else
                {
                    sb.Append("?");
                    // Add pageID to URL
                    sb.Append("pageId=");
                    sb.Append(pageID.ToString());

                    // Add Alias to URL
                    if (_aliasInUrl)
                    {
                        sb.Append("&alias="); // changed for compatibility with handler
                        sb.Append(currentAlias);
                    }

                    // Add ModID to URL
                    if (modID > 0)
                    {
                        sb.Append("&mid=");
                        sb.Append(modID.ToString());
                    }

                    // Add Language to URL
                    if (_langInUrl && culture != null)
                    {
                        sb.Append("&lang=");     // changed for compatibility with handler
                        sb.Append(culture.Name); // manu fix: culture.Name
                    }

                    // Add custom attributes
                    if (customAttributes != null && customAttributes != string.Empty)
                    {
                        sb.Append("&");
                        customAttributes = customAttributes.ToString().Replace("/", "&");
                        customAttributes = customAttributes.ToString().Replace(_defaultSplitter, "=");
                        sb.Append(customAttributes);
                    }
                    return(sb.ToString().Replace("&&", "&"));
                }
            }
            else // use handler
            {
                // Add smarturl tag
                if (!string.IsNullOrEmpty(_handlerFlag))
                {
                    sb.Append(_handlerFlag);
                    sb.Append("/");
                }

                // Add custom Keywords to the Url
                if (urlKeywords != null && urlKeywords != string.Empty)
                {
                    sb.Append(urlKeywords);
                    sb.Append("/");
                }
                else
                {
                    urlKeywords = urlElements.UrlKeywords;

                    // Add custom Keywords to the Url
                    if (urlKeywords != null && urlKeywords.Length != 0)
                    {
                        sb.Append(urlKeywords);
                        sb.Append("/");
                    }
                }

                // Add Alias to URL
                if (_aliasInUrl)
                {
                    sb.Append("alias");
                    sb.Append(_defaultSplitter + currentAlias);
                    sb.Append("/");
                }

                // Add Language to URL
                if (_langInUrl && culture != null)
                {
                    sb.Append("lang");
                    sb.Append(_defaultSplitter + culture.Name);
                    sb.Append("/");
                }
                // Add ModID to URL
                if (modID > 0)
                {
                    sb.Append("mid");
                    sb.Append(_defaultSplitter + modID.ToString());
                    sb.Append("/");
                }

                string queryLeft  = "";
                string queryRigth = "";

                // Add custom attributes
                if (customAttributes != null && customAttributes != string.Empty)
                {
                    var parts = customAttributes.Split(new char[] { '&' }, StringSplitOptions.RemoveEmptyEntries);

                    for (int i = 0; i < parts.Length; i++)
                    {
                        try {
                            var key = parts[i].Split('=')[0];
                            if (!(key.Equals("pageId") || key.Equals("pageID")))
                            {
                                if (queryList.ContainsKey(key))
                                {
                                    var q = parts[i].Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
                                    queryRigth += HttpUtility.UrlEncode(q[0], System.Text.Encoding.GetEncoding(28591)) + "=" + HttpUtility.UrlEncode(q[1], System.Text.Encoding.GetEncoding(28591)) + "&";
                                }
                                else
                                {
                                    var q = parts[i].Split('=');
                                    queryLeft += HttpUtility.UrlEncode(q[0], System.Text.Encoding.GetEncoding(28591)) + "=" + HttpUtility.UrlEncode(q[1], System.Text.Encoding.GetEncoding(28591)) + "&";
                                }
                            }
                        }
                        catch (Exception) { }
                    }

                    if (!string.IsNullOrEmpty(queryLeft))
                    {
                        // If its null, all the attributes are at the end, else, should add the ones from the queryLeft
                        queryLeft = queryLeft.Remove(queryLeft.Length - 1);
                        queryLeft = queryLeft.Replace("+", "%20");
                        queryLeft = queryLeft.ToString().Replace("&", "/");
                        queryLeft = queryLeft.ToString().Replace("=", _defaultSplitter);
                        sb.Append(queryLeft);
                        sb.Append("/");
                    }
                }


                sb.Append(pageID);
                sb.Append("/");


                if (!string.IsNullOrEmpty(urlElements.PageName))// TODO : Need to fix page names rewrites
                {
                    sb.Append(urlElements.PageName);
                }
                else
                if (!string.IsNullOrEmpty(urlElements.PageTitle))
                {
                    string PageName = urlElements.PageTitle;
                    // Write page Hieranchy
                    if (Hieranchy)
                    {
                        var settings = (PortalSettings)HttpContext.Current.Items["PortalSettings"];
                        int parentId = 0;

                        bool found = false;
                        //Get the parent pageId of the actual pageId
                        for (int i = 0; i < settings.DesktopPages.Count && !found; i++)
                        {
                            if (settings.DesktopPages[i].PageID == pageID)
                            {
                                parentId = settings.DesktopPages[i].ParentPageID;
                                found    = true;
                            }
                        }
                        if (found)
                        {
                            bool exit = false;
                            // while the parentId it's diferent of 0 or the parentId isn't in settings
                            while (parentId != 0 && !exit)
                            {
                                found = false;
                                // find the parent in the setting
                                for (int i = 0; i < settings.DesktopPages.Count && !found; i++)
                                {
                                    if (settings.DesktopPages[i].PageID == parentId)
                                    {
                                        PageName = UrlBuilderHelper.CleanNoAlphanumerics(settings.DesktopPages[i].PageName) + "/" + PageName;
                                        parentId = settings.DesktopPages[i].ParentPageID;
                                        found    = true;
                                    }
                                }
                                // If the parent isn't in settings the loop should stop
                                if (!found)
                                {
                                    exit = true;
                                }
                            }
                        }
                    }
                    sb.Append(PageName);
                }
                else
                {
                    sb.Append(_friendlyPageName);
                }

                // Add the query at the end
                if (!string.IsNullOrEmpty(queryRigth))
                {
                    queryRigth = queryRigth.Remove(queryRigth.Length - 1);
                    sb.Append("?" + queryRigth);
                }

                //Return page
                return(sb.ToString().Replace("//", "/"));
            }
        }
コード例 #3
0
        /// <summary>
        /// This method is used to get all Url Elements in one go
        /// </summary>
        /// <param name="pageID">The ID of the page you are interested in</param>
        /// <param name="cacheDuration">The length of time these values should be cached once retrieved</param>
        /// <param name="_isPlaceHolder">Is this url a place holder (Not a real url)</param>
        /// <param name="_tabLink">Is this Url a link to an external site/resource</param>
        /// <param name="_urlKeywords">Are there any keywords that should be added to this url</param>
        /// <param name="_pageName">Does this url have a friendly page name other than the default</param>
        public static UrlElements GetUrlElements(int pageID, double cacheDuration)
        {
            UrlElements urlElements = new UrlElements();

            // pageID 0 is a default page shared across portals with no real settings
            if (pageID == 0)
                return urlElements;

            string urlElementsCacheKey = UrlElementsCacheKey(pageID);

            // calling HttpContext.Current.Cache all the time incurs a small performance hit so get a reference to it once and reuse that for greater performance
            Cache applicationCache = HttpContext.Current.Cache;

            // if any values are null refetch
            if (applicationCache[urlElementsCacheKey] == null)
            {
                using (SqlConnection conn = new SqlConnection(SiteConnectionString))
                {
                    try
                    {
                        // Open the connection
                        conn.Open();

                        using (SqlCommand cmd = new SqlCommand(GetUrlElementsQuery, conn))
                        {
                            var parameterPageId = new SqlParameter("@PageID", SqlDbType.Int, 4) { Value = pageID };
                            cmd.Parameters.Add(parameterPageId);

                            SqlDataReader pageElements = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                            if (pageElements.HasRows)
                            {
                                pageElements.Read();

                                urlElements.PageName = Convert.ToString(pageElements["PageSEOName"]);
                                if (!String.IsNullOrEmpty(urlElements.PageName))
                                    urlElements.PageName = CleanNoAlphanumerics(urlElements.PageName);

                                urlElements.PageTitle = Convert.ToString(pageElements["PageTitle"]);
                                if (!String.IsNullOrEmpty(urlElements.PageTitle))
                                    urlElements.PageTitle = CleanNoAlphanumerics(urlElements.PageTitle);

                                urlElements.UrlKeywords = Convert.ToString(pageElements["Keywords"]);
                                if (!String.IsNullOrEmpty(urlElements.UrlKeywords))
                                    urlElements.UrlKeywords = CleanNoAlphanumerics(urlElements.UrlKeywords);

                                urlElements.TabLink = Convert.ToString(pageElements["ExternalLink"]);

                                if (pageElements["IsPlaceHolder"].ToString() != String.Empty)
                                {
                                    urlElements.IsPlaceHolder = bool.Parse(pageElements["IsPlaceHolder"].ToString());
                                }
                                // insert value in cache so it doesn't always try to retrieve it

                                // NOTE: This is the tabsettings Cache Dependency approach see note above
                                // applicationCache.Insert(isPlaceHolderKey, _isPlaceHolder.ToString(), new CacheDependency(null, dependencyKey));
                                if (cacheDuration == 0)
                                {
                                    applicationCache.Insert(urlElementsCacheKey, urlElements);
                                }
                                else
                                {
                                    applicationCache.Insert(urlElementsCacheKey, urlElements, null, DateTime.Now.AddMinutes(cacheDuration), Cache.NoSlidingExpiration);
                                }
                            }
                            // close the reader
                            pageElements.Close();
                        }
                    }
                    catch
                    {
                        // TODO: Decide whether or not this should be logged. If it is a large site upgrading then it would quickly fill up a log file.
                        // If there is no value in the database then it thows an error as it is expecting something.
                        // This can happen with the initial setup or if no entries for a tab have been made
                    }

                    finally
                    {
                        // Close the connection
                        if (conn != null)
                            conn.Close();
                    }
                }
            }
            else
            {
                urlElements = (UrlElements)applicationCache[urlElementsCacheKey];
            }
            return urlElements;
        }
コード例 #4
0
        /// <summary>
        /// Takes a Tab ID and builds the url for get the desidered page (non default)
        /// containing the application path, portal alias, tab ID, and language.
        /// </summary>
        /// <param name="targetPage">Linked page</param>
        /// <param name="pageID">ID of the page</param>
        /// <param name="modID">ID of the module</param>
        /// <param name="culture">Client culture</param>
        /// <param name="customAttributes">Any custom attribute that can be needed. Use the following format...single attribute: paramname--paramvalue . Multiple attributes: paramname--paramvalue/paramname2--paramvalue2/paramname3--paramvalue3 </param>
        /// <param name="currentAlias">Current Alias</param>
        /// <param name="urlKeywords">Add some keywords to uniquely identify this tab. Usual source is UrlKeyword from TabSettings.</param>
        public override string BuildUrl(string targetPage, int pageID, int modID, CultureInfo culture,
                                        string customAttributes, string currentAlias, string urlKeywords)
        {
            // Get Url Elements this helper method (Will either retrieve from cache or database)
            UrlElements urlElements = UrlBuilderHelper.GetUrlElements(pageID, _cacheMinutes);

            //2_aug_2004 Cory Isakson
            //Begin Navigation Enhancements
            if (!(targetPage.ToLower().EndsWith(_ignoreTargetPage.ToLower())))
            // Do not modify URLs when working with TabLayout Administration Page
            {
                // if it is a placeholder it is not supposed to have any url
                if (urlElements.IsPlaceHolder)
                {
                    return(string.Empty);
                }

                // if it is a tab link it means it is a link to an external resource
                //if (urlElements.TabLink.Length != 0) return urlElements.TabLink;
                if (urlElements.TabLink.Length != 0)
                {
                    if (urlElements.TabLink.ToLower().Contains("http://") || urlElements.TabLink.ToLower().Contains("https://"))
                    {
                        return(urlElements.TabLink);
                    }
                    else
                    {
                        return("http://" + urlElements.TabLink);
                    }
                }
            }
            //End Navigation Enhancements

            if (targetPage.StartsWith("~/"))
            {
                targetPage = targetPage.Substring(2);
            }

            //[email protected] - 2014/12/24 - Added for getting friendly url from cache
            PageUrl pageurl  = GetCachePageUrl(pageID);
            string  cacheUrl = string.Empty;

            if (pageurl != null && (targetPage.Equals(HttpUrlBuilder.DefaultPage) || targetPage.Equals("DesktopDefault.aspx")))
            {
                if (PortalSettings.HasEnablePageFriendlyUrl(pageID, currentAlias))
                {
                    if (!string.IsNullOrEmpty(pageurl.PageFriendlyUrl))
                    {
                        return(pageurl.PageFriendlyUrl);
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(pageurl.PageNormalUrl))
                    {
                        return(pageurl.PageNormalUrl);
                    }
                }
            }


            StringBuilder sb = new StringBuilder();

            // Obtain ApplicationPath
            if (targetPage.StartsWith("~/"))
            {
                sb.Append(UrlBuilderHelper.ApplicationPath);
                targetPage = targetPage.Substring(2);
            }
            sb.Append("/");

            //if (!targetPage.EndsWith(".aspx")) //Images
            //{
            //    sb.Append(targetPage);
            //    return sb.ToString();
            //}

            HttpContext.Current.Trace.Warn("Target Page = " + targetPage);

            // Separate path
            // If page contains path, or it is not an aspx
            // or handlerFlag is not set: do not use handler
            if (!targetPage.Equals(HttpUrlBuilder.DefaultPage) && !targetPage.Equals("DesktopDefault.aspx"))
            {
                sb.Append(targetPage);
                // if !!targetPage.EndsWith(".aspx") it's an image. Return
                if (!targetPage.EndsWith(".aspx"))
                {
                    return(sb.ToString());
                }
                else
                {
                    sb.Append("?");
                    // Add pageID to URL
                    sb.Append("pageId=");
                    sb.Append(pageID.ToString());

                    // Add Alias to URL
                    if (_aliasInUrl)
                    {
                        sb.Append("&alias="); // changed for compatibility with handler
                        sb.Append(currentAlias);
                    }

                    // Add ModID to URL
                    if (modID > 0)
                    {
                        sb.Append("&mid=");
                        sb.Append(modID.ToString());
                    }

                    // Add Language to URL
                    if (_langInUrl && culture != null)
                    {
                        sb.Append("&lang=");     // changed for compatibility with handler
                        sb.Append(culture.Name); // manu fix: culture.Name
                    }

                    // Add custom attributes
                    if (customAttributes != null && customAttributes != string.Empty)
                    {
                        sb.Append("&");
                        customAttributes = customAttributes.ToString().Replace("/", "&");
                        customAttributes = customAttributes.ToString().Replace(_defaultSplitter, "=");
                        sb.Append(customAttributes);
                    }
                    return(sb.ToString().Replace("&&", "&"));
                }
            }
            else // use handler
            {
                PortalSettings settings     = PortalSettings.GetPortalSettingsbyPageID(pageID, currentAlias);
                var            hasFriendUrl = false;
                if (settings.EnablePageFriendlyUrl)
                {
                    PagesDB pages = new PagesDB();
                    //[email protected] - 2014/12/16 - Get friendlyUrl from database
                    var friendlyURL = pages.GetFriendlyURl(pageID);
                    //[email protected] - 2014/12/16 - Check friendlyUrl not null
                    if (friendlyURL != "")
                    {
                        hasFriendUrl = true;
                        sb.Append(friendlyURL).ToString();
                    }
                }

                string queryLeft  = "";
                string queryRigth = "";

                // Add custom attributes
                #region custom attributes
                if (customAttributes != null && customAttributes != string.Empty)
                {
                    var parts = customAttributes.Split(new char[] { '&' }, StringSplitOptions.RemoveEmptyEntries);

                    for (int i = 0; i < parts.Length; i++)
                    {
                        try
                        {
                            var key = parts[i].Split('=')[0];
                            if (!(key.Equals("pageId") || key.Equals("pageID")))
                            {
                                if (queryList.ContainsKey(key))
                                {
                                    var q = parts[i].Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
                                    queryRigth += HttpUtility.UrlEncode(q[0], System.Text.Encoding.GetEncoding(28591)) + "=" + HttpUtility.UrlEncode(q[1], System.Text.Encoding.GetEncoding(28591)) + "&";
                                }
                                else
                                {
                                    var q = parts[i].Split('=');
                                    queryLeft += HttpUtility.UrlEncode(q[0], System.Text.Encoding.GetEncoding(28591)) + "=" + HttpUtility.UrlEncode(q[1], System.Text.Encoding.GetEncoding(28591)) + "&";
                                }
                            }
                        }
                        catch (Exception) { }
                    }

                    if (!string.IsNullOrEmpty(queryLeft))
                    {
                        // If its null, all the attributes are at the end, else, should add the ones from the queryLeft
                        queryLeft = queryLeft.Remove(queryLeft.Length - 1);
                        queryLeft = queryLeft.Replace("+", "%20");
                        queryLeft = queryLeft.ToString().Replace("&", "/");
                        queryLeft = queryLeft.ToString().Replace("=", _defaultSplitter);
                    }
                }
                #endregion

                if (!hasFriendUrl)
                {
                    #region Existing Url Builing code
                    // Add smarturl tag and if friendlyURL false
                    if (!string.IsNullOrEmpty(_handlerFlag) && !settings.EnablePageFriendlyUrl)
                    {
                        sb.Append(_handlerFlag);
                        sb.Append("/");
                    }

                    // Add custom Keywords to the Url
                    if (urlKeywords != null && urlKeywords != string.Empty)
                    {
                        sb.Append(urlKeywords);
                        sb.Append("/");
                    }
                    else
                    {
                        urlKeywords = urlElements.UrlKeywords;

                        // Add custom Keywords to the Url
                        if (urlKeywords != null && urlKeywords.Length != 0)
                        {
                            sb.Append(urlKeywords);
                            sb.Append("/");
                        }
                    }

                    // Add Alias to URL
                    if (_aliasInUrl)
                    {
                        sb.Append("alias");
                        sb.Append(_defaultSplitter + currentAlias);
                        sb.Append("/");
                    }

                    // Add Language to URL
                    if (_langInUrl && culture != null)
                    {
                        sb.Append("lang");
                        sb.Append(_defaultSplitter + culture.Name);
                        sb.Append("/");
                    }
                    // Add ModID to URL
                    if (modID > 0)
                    {
                        sb.Append("mid");
                        sb.Append(_defaultSplitter + modID.ToString());
                        sb.Append("/");
                    }

                    if (!string.IsNullOrEmpty(queryLeft))
                    {
                        sb.Append(queryLeft);
                        sb.Append("/");
                    }

                    //get setting from portalsettings
                    //HttpContext.Item - add/update key all the codes are managed by this method
                    //PortalSettings settings = PortalSettings.GetPortalSettingsbyPageID(Portal.PageID, Portal.UniqueID);

                    //[email protected] - 2014/12/16 - Appends if EnableFrindlyURl is false
                    if (!settings.EnablePageFriendlyUrl)
                    {
                        sb.Append(pageID);
                        sb.Append("/");
                    }

                    if (!string.IsNullOrEmpty(urlElements.PageName))// TODO : Need to fix page names rewrites
                    {
                        sb.Append(urlElements.PageName);
                    }
                    else
                    if (!string.IsNullOrEmpty(urlElements.PageTitle))
                    {
                        string PageName = urlElements.PageTitle;
                        // Write page Hieranchy
                        if (Hieranchy)
                        {
                            int parentId = 0;

                            bool found = false;
                            //Get the parent pageId of the actual pageId
                            for (int i = 0; i < settings.DesktopPages.Count && !found; i++)
                            {
                                if (settings.DesktopPages[i].PageID == pageID)
                                {
                                    parentId = settings.DesktopPages[i].ParentPageID;
                                    found    = true;
                                }
                            }
                            if (found)
                            {
                                bool exit = false;
                                // while the parentId it's diferent of 0 or the parentId isn't in settings
                                while (parentId != 0 && !exit)
                                {
                                    found = false;
                                    // find the parent in the setting
                                    for (int i = 0; i < settings.DesktopPages.Count && !found; i++)
                                    {
                                        if (settings.DesktopPages[i].PageID == parentId)
                                        {
                                            PageName = UrlBuilderHelper.CleanNoAlphanumerics(settings.DesktopPages[i].PageName) + "/" + PageName;
                                            parentId = settings.DesktopPages[i].ParentPageID;
                                            found    = true;
                                        }
                                    }
                                    // If the parent isn't in settings the loop should stop
                                    if (!found)
                                    {
                                        exit = true;
                                    }
                                }
                            }
                        }
                        sb.Append(PageName);
                    }
                    else
                    {
                        sb.Append(_friendlyPageName);
                    }

                    #endregion
                }

                // [email protected] - 2014/12/16 -
                // check friendly URL is enabled and requested file is exist physically or not.
                // If not exists and friendly url is enabled, the extension will be appended.
                if (settings.EnablePageFriendlyUrl &&
                    !System.IO.File.Exists(HttpContext.Current.Server.MapPath(sb.ToString())) && !_friendlyUrlNoExtension)
                {
                    sb.Append(this._friendlyUrlExtension);
                }

                // Add the query at the end
                if (!string.IsNullOrEmpty(queryRigth))
                {
                    queryRigth = queryRigth.Remove(queryRigth.Length - 1);
                    sb.Append("?" + queryRigth);
                }

                //[email protected] - 2014/12/24 - Modified for setting friendly url into cache
                var url = sb.ToString().Replace("//", "/");
                if (settings.EnablePageFriendlyUrl)
                {
                    SetCachePageUrl(pageID, string.Empty, url);
                }
                else
                {
                    SetCachePageUrl(pageID, url, string.Empty);
                }

                return(url);
            }
        }