/// <summary> /// Get PageFriendlyURL by PageID /// If exist then return otherwise emplty /// </summary> /// <param name="pageID">PageID</param> /// <returns>FriendlyURL</returns> private static string GetFriendlyURlbyPageID(int pageID) { PagesDB pages = new PagesDB(); //Get FriendlyURL from DB by pageid return(pages.GetFriendlyURl(pageID)); }
/// <summary> /// Get the friendlyURL by selecting the page /// </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 drpPageList_SelectedIndexChanged(object sender, EventArgs e) { divErrorMessage.Visible = false; divSuccessMessage.Visible = false; divDyanamicPage.Visible = (drpPageList.SelectedValue == "-1"); if (drpPageList.SelectedValue != "-1") { btnSaveWithoutExtension.Visible = false; PagesDB pages = new PagesDB(); // Get and Set friendlyURL from db to Textbox when change the dropdown value txtFriendlyURL.Text = pages.GetFriendlyURl(Convert.ToInt32(drpPageList.SelectedValue)); } else { btnSaveWithoutExtension.Visible = true; } }
/// <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); } }