Пример #1
0
        /// <summary>
        /// Get pageId from pagename
        /// </summary>
        /// <returns>PageID</returns>
        public static string GetPageIDFromPageName(string pagepath)
        {
            PagesDB DB       = new PagesDB();
            var     settings = PortalSettings.GetPortalSettingsbyPageID(Portal.PageID, Config.DefaultPortal);

            int portalID = 0;

            if (settings != null)
            {
                portalID = settings.PortalID;
            }

            DataTable dtPages = DB.GetPagesFlatTable(portalID);

            //When friendly URl applied and go to Home page from and sub pages
            if (pagepath.ToLower().Contains("default.aspx"))
            {
                string page_ID = "1";
                return(page_ID);
            }

            // Check requested page url contains the /site when friendly URL is on
            var handlerFlag = System.Configuration.ConfigurationManager.AppSettings["handlerFlag"];

            if (pagepath.Contains("/" + handlerFlag))
            {
                string[] splitpaths       = pagepath.Split('/');
                int      index            = Array.IndexOf(splitpaths, handlerFlag);
                int      requesetedPageId = Convert.ToInt32(splitpaths[index + 1]);
                pagepath = HttpUrlBuilder.BuildUrl(requesetedPageId);
            }

            foreach (DataRow pageRow in dtPages.Rows)
            {
                int    pageId = Convert.ToInt32(pageRow["PageID"]);
                string url    = HttpUrlBuilder.BuildUrl(pageId);
                if (url.ToLower() == pagepath.ToLower())
                {
                    return(pageId.ToString());
                }
            }

            string dynamicPage = DB.GetDynamicPageUrl(pagepath);

            if (!string.IsNullOrEmpty(dynamicPage))
            {
                //-1 for dynamic pages
                return("-1");
            }

            // if page is not found it will throw 404 error
            throw new HttpException(404, "Page not Found", 3);
        }
Пример #2
0
        /// <summary>
        /// Rewrites the URL.
        /// </summary>
        /// <param name="url">The URL to rewrite.</param>
        /// <returns>The rewritten URL.</returns>
        public override string RewriteUrl(string url)
        {
            var handler      = string.Format("/{0}", this.handlerFlag);
            var rewrittenUrl = "";

            var settings = PortalSettings.GetPortalSettingsbyPageID(Portal.PageID, Config.DefaultPortal);

            // [email protected] - 2014/12/16 -  Only when Url contains handler and EnablePageFriendlyUrl = false
            if (url.Contains(handler) && !settings.EnablePageFriendlyUrl)
            {
                rewrittenUrl = url.Substring(0, url.IndexOf(handler));
            }

            var parts = url.Substring(url.IndexOf(handler) + handler.Length).Split(new char[] { '/' }, System.StringSplitOptions.RemoveEmptyEntries);

            rewrittenUrl += string.Format("/{0}", this.friendlyPageName);

            var   pageId = "0"; //this is made in order to allow urls formed only with the handler (/site/ been the default). Those urls will be redirected to the portal home.
            Regex regex  = new Regex("^\\d+$", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            // Need to search for the pageId in the url
            int indexNumber = -1;

            // [email protected] - 2014/12/16 -
            //Set the pageid If Enable frindly Url is false
            // if true then set the pageid from URLRewriteFriendlyUrl class
            if (!settings.EnablePageFriendlyUrl)
            {
                for (int i = 0; i < parts.Length && indexNumber == -1; i++)
                {
                    if (regex.IsMatch(parts[i]))
                    {
                        indexNumber = i;
                    }
                }
                if (url.Contains("alias" + this.defaultSplitter))
                {
                    pageId = 0.ToString();
                }
                else if (indexNumber != -1)
                {
                    pageId = parts[indexNumber];
                }
            }
            else
            {
                // [email protected] - 2014/12/16 -  Set when EnableFriendlyUrl is true
                pageId = UrlRewritingFriendlyUrl.GetPageIDFromPageName(url);
            }

            var queryString = string.Format("?pageId={0}", pageId);

            if (parts.Length > 2)
            {
                for (var i = 0; i < indexNumber; i++)
                {
                    var queryStringParam = parts[i];

                    if (queryStringParam.IndexOf(this.defaultSplitter) < 0)
                    {
                        continue;
                    }

                    queryString += string.Format(
                        "&{0}={1}",
                        queryStringParam.Substring(0, queryStringParam.IndexOf(this.defaultSplitter)),
                        queryStringParam.Substring(queryStringParam.IndexOf(this.defaultSplitter) + this.defaultSplitter.Length));
                }
            }
            if (HttpContext.Current.Request.Form["signed_request"] != null)
            {
                queryString += string.Format(
                    "&signed_request={0}",
                    HttpContext.Current.Request.Params["signed_request"]);
            }

            HttpContext.Current.RewritePath(rewrittenUrl, string.Empty, queryString);

            return(rewrittenUrl + queryString);
        }
Пример #3
0
        /// <summary>
        /// Handles the BeginRequest event of the AppleseedApplication control.
        /// </summary>
        /// <param name="sender">
        /// The source of the event.
        /// </param>
        /// <param name="e">
        /// The <see cref="System.EventArgs"/> instance containing the event data.
        /// </param>
        protected void AppleseedApplication_BeginRequest(object sender, EventArgs e)
        {
            string rawUrlLower = Request.RawUrl.ToLower();

            if (rawUrlLower != "/" && !rawUrlLower.Contains("/installer") && !rawUrlLower.Contains("/webresource.axd") && !File.Exists(Server.MapPath(rawUrlLower.Split('?')[0])))
            {
                Appleseed.Framework.Site.Data.PagesDB pagedb = new Framework.Site.Data.PagesDB();
                string redirectToUrl = pagedb.GetDynamicPageUrl(rawUrlLower);
                if (!string.IsNullOrEmpty(redirectToUrl))
                {
                    Response.Redirect(redirectToUrl, true);
                    return;
                }
            }
            //Appleseed.Framework.Site.Data.PagesDB pagedb = new Framework.Site.Data.PagesDB();
            //string redirectToUrl = pagedb.GetDynamicPageUrl(Request.RawUrl);
            //if (!string.IsNullOrEmpty(redirectToUrl))
            //{
            //    Response.Redirect(redirectToUrl, true);
            //    return;
            //}
            string Addwww = System.Configuration.ConfigurationManager.AppSettings.Get("AddWwwToRequest");

            if (Addwww != null && Addwww.Equals("true"))
            {
                if (!Request.IsSecureConnection)
                {
                    if (!Request.Url.AbsoluteUri.ToLower().Contains("www"))
                    {
                        var newUrl = Request.Url.AbsoluteUri.Replace("http://", "http://www.");
                        Response.Redirect(newUrl, true);
                    }
                }
            }

            /*Send a signal to allow custom js registration (not enabled yet)*/
            Bus.Send(new JSRegisterDescriptor()
            {
                Scripts = new List <string>()
            });

            var contextReader = new Reader(new WebContextReader());
            var context       = contextReader.Current;

            var currentUrl = context.Request.Path.ToLower();

            if (Debugger.IsAttached && currentUrl.Contains("trace.axd"))
            {
                return;
            }

            context.Trace.Warn("Application_BeginRequest :: " + currentUrl);
            if (Portal.PageID > 0)
            {
                var physicalPath = context.Server.MapPath(currentUrl.Substring(currentUrl.LastIndexOf("/") + 1));

                if (!File.Exists(physicalPath))
                {
                    // Rewrites the path
                    context.RewritePath("~/default.aspx?" + context.Request.ServerVariables["QUERY_STRING"]);
                }
            }
            else
            {
                var pname = currentUrl.Substring(currentUrl.LastIndexOf("/") + 1);

                // if the request was not caused by an MS Ajax Client script invoking a WS.
                if (!currentUrl.ToLower().EndsWith(".asmx/js"))
                {
                    if (!String.IsNullOrEmpty(pname) && pname.Length > 5)
                    {
                        pname = pname.Substring(0, pname.Length - 5);
                    }

                    if (Regex.IsMatch(pname, @"^\d+$"))
                    {
                        context.RewritePath(
                            string.Format(
                                "~/default.aspx?pageid={0}&{1}", pname, context.Request.ServerVariables["QUERY_STRING"]));
                    }
                }
            }

            // 1st Check: is it a dangerously malformed request?
            #region
            // Important patch http://support.microsoft.com/?kbid=887459
            if (context.Request.Path.IndexOf('\\') >= 0 ||
                Path.GetFullPath(context.Request.PhysicalPath) != context.Request.PhysicalPath)
            {
                throw new AppleseedRedirect(LogLevel.Warn, HttpStatusCode.NotFound, "Malformed request", null);
            }

            #endregion

            // 2nd Check: is the AllPortals Lock switched on?
            // let the user through if client IP address is in LockExceptions list, otherwise throw...
            #region
            if (Config.LockAllPortals)
            {
                var rawUrl       = context.Request.RawUrl.ToLower(CultureInfo.InvariantCulture);
                var lockRedirect = Config.LockRedirect;
                if (!rawUrl.EndsWith(lockRedirect))
                {
                    // construct IPList
                    var lockKeyHolders = Config.LockKeyHolders.Split(new[] { ';' });
                    var ipList         = new IPList();
                    foreach (var lockKeyHolder in lockKeyHolders)
                    {
                        if (lockKeyHolder.IndexOf("-") > -1)
                        {
                            ipList.AddRange(
                                lockKeyHolder.Substring(0, lockKeyHolder.IndexOf("-")),
                                lockKeyHolder.Substring(lockKeyHolder.IndexOf("-") + 1));
                        }
                        else
                        {
                            ipList.Add(lockKeyHolder);
                        }
                    }

                    // check if requestor's IP address is in allowed list
                    if (!ipList.CheckNumber(context.Request.UserHostAddress))
                    {
                        throw new PortalsLockedException();
                    }
                }
            }
            #endregion

            // 3rd Check: is database/code version correct?
            var requestUri      = context.Request.Url;
            var requestPath     = requestUri.AbsolutePath.ToLower(CultureInfo.InvariantCulture);
            var returnToRequest = CheckAndUpdateDB(context, requestPath);


            if (returnToRequest)
            {
                return;
            }

            // Get portalsettings and add both key "PortalSettings","PortalID" into the Context.Item if not exisit
            // All neccessory checks and oprations are managed by this method
            //[email protected] - 2014/12/16 - Get portalsettings by pageid and portal id
            PortalSettings portalSettings = PortalSettings.GetPortalSettingsbyPageID(Portal.PageID, Portal.UniqueID);

            Membership.Provider.ApplicationName     = portalSettings.PortalAlias;
            ProfileManager.Provider.ApplicationName = portalSettings.PortalAlias;
            Roles.ApplicationName = portalSettings.PortalAlias;

            var smartErrorRedirect = Config.SmartErrorRedirect;
            if (smartErrorRedirect.StartsWith("~/"))
            {
                smartErrorRedirect = smartErrorRedirect.TrimStart(new[] { '~' });
            }

            if (requestPath.EndsWith(smartErrorRedirect.ToLower(CultureInfo.InvariantCulture)))
            {
                return; // this is SmartError page... so continue
            }

            // WLF: This was backwards before so it would always set refreshSite true because the cookie was changed before it was checked.
            // WLF: REVIEW: This whole section needs a code review.
            // Try to get alias from cookie to determine if alias has been changed
            var refreshSite       = false;
            var portalAliasCookie = context.Request.Cookies["PortalAlias"];
            if (portalAliasCookie != null && portalAliasCookie.Value.ToLower() != Portal.UniqueID)
            {
                refreshSite = true; // Portal has changed since last page request
            }

            if (portalSettings != null)
            {
                portalAliasCookie = new HttpCookie("PortalAlias")
                {
                    Path = "/", Value = portalSettings.PortalAlias
                };
                if (context.Response.Cookies["PortalAlias"] == null)
                {
                    context.Response.Cookies.Add(portalAliasCookie);
                }
                else
                {
                    context.Response.Cookies.Set(portalAliasCookie);
                }
            }

            // if switching portals then clean parameters [TipTopWeb]
            // Must be the last instruction in this method
            var refreshedCookie = context.Request.Cookies["refreshed"];

            // 5/7/2006 Ed Daniel
            // Added hack for Http 302 by extending condition below to check for more than 3 cookies
            if (refreshSite && context.Request.Cookies.Keys.Count > 3)
            {
                // Sign out and force the browser to refresh only once to avoid any dead-lock
                if (refreshedCookie == null || refreshedCookie.Value == "false")
                {
                    var rawUrl             = context.Request.RawUrl;
                    var newRefreshedCookie = new HttpCookie("refreshed", "true")
                    {
                        Path    = "/",
                        Expires = DateTime.Now.AddMinutes(1)
                    };
                    if (refreshedCookie == null)
                    {
                        context.Response.Cookies.Add(newRefreshedCookie);
                    }
                    else
                    {
                        context.Response.Cookies.Set(newRefreshedCookie);
                    }

                    var msg =
                        string.Format(
                            "User logged out on global.asax line 423. Values -> refreshsite: {0}, context.Request.Cookies.Keys.count: {1}, rawurl: {2}",
                            refreshSite,
                            context.Request.Cookies.Keys.Count,
                            rawUrl);

                    ErrorHandler.Publish(
                        LogLevel.Warn,
                        msg);

                    // sign-out, if refreshed parameter on the command line we will not call it again
                    PortalSecurity.SignOut(rawUrl, false);
                }
            }

            // invalidate cookie, so the page can be refreshed when needed
            refreshedCookie = context.Request.Cookies["refreshed"];
            if (refreshedCookie != null && context.Request.Cookies.Keys.Count > 3)
            {
                var newRefreshedCookie = new HttpCookie("refreshed", "false")
                {
                    Path    = "/",
                    Expires = DateTime.Now.AddMinutes(1)
                };
                context.Response.Cookies.Set(newRefreshedCookie);
            }

            // This is done in order to allow the sitemap to reference a page that is outside this website.
            var targetPage = this.Request.Params["sitemapTargetPage"];
            if (!string.IsNullOrEmpty(targetPage))
            {
                int mvcPageId;
                if (int.TryParse(targetPage, out mvcPageId))
                {
                    var url = HttpUrlBuilder.BuildUrl(mvcPageId);
                    this.Response.Redirect(url);
                }
            }
        }
Пример #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);
            }
        }