public void DeleteTabUrl(TabUrlInfo tabUrl, int portalId, bool clearCache) { DataProvider.Instance().DeleteTabUrl(tabUrl.TabId, tabUrl.SeqNum); if (clearCache) { DataCache.RemoveCache(String.Format(DataCache.TabUrlCacheKey, portalId)); var tab = GetTab(tabUrl.TabId, portalId); tab.ClearTabUrls(); } }
protected void gvCustomUrls_InsertCommand(object sender, GridCommandEventArgs e) { GridEditableItem editedItem = e.Item as GridEditableItem; DropDownList ddlPortalAliasId = editedItem.FindControl("ddlPortalAliasId") as DropDownList; DropDownList ddlPortalAliasUsage = editedItem.FindControl("ddlPortalAliasUsage") as DropDownList; DropDownList ddlHttpStatus = editedItem.FindControl("ddlHttpStatus") as DropDownList; Hashtable ht = new Hashtable(); editedItem.ExtractValues(ht); // increment existing tabUrls List <TabUrlInfo> tabUrls = DotNetNuke.Entities.Tabs.Internal.TestableTabController.Instance.GetTabUrls(ddlPage.SelectedItemValueAsInt, PortalId); foreach (TabUrlInfo tu in tabUrls) { tu.SeqNum++; DotNetNuke.Entities.Tabs.Internal.TestableTabController.Instance.SaveTabUrl(tu, PortalId, false); } // create new tabUrl TabUrlInfo tabUrl = new TabUrlInfo(); tabUrl.TabId = ddlPage.SelectedItemValueAsInt; tabUrl.SeqNum = 0; tabUrl.CultureCode = this.PortalSettings.CultureCode; if (!string.IsNullOrEmpty(ddlPortalAliasId.SelectedValue)) { tabUrl.PortalAliasId = int.Parse(ddlPortalAliasId.SelectedValue); } if (!string.IsNullOrWhiteSpace(ddlPortalAliasUsage.SelectedValue)) { tabUrl.PortalAliasUsage = (PortalAliasUsageType)Enum.Parse(typeof(PortalAliasUsageType), ddlPortalAliasUsage.SelectedValue); } if (ht["Url"] != null) { tabUrl.Url = FriendlyUrlController.EnsureLeadingChar("/", ht["Url"].ToString()); } if (ht["QueryString"] != null) { tabUrl.QueryString = ht["QueryString"].ToString(); } tabUrl.HttpStatus = ddlHttpStatus.SelectedValue; tabUrl.IsSystem = false; DotNetNuke.Entities.Tabs.Internal.TestableTabController.Instance.SaveTabUrl(tabUrl, PortalId, true); DotNetNuke.Common.Utilities.DataCache.ClearCache(); }
public PageUrlResult DeleteCustomUrl(int id, TabInfo tab) { PortalSettings portalSettings = PortalController.Instance.GetCurrentSettings() as PortalSettings; TabUrlInfo tabUrl = tab.TabUrls.SingleOrDefault(u => u.SeqNum == id); TabController.Instance.DeleteTabUrl(tabUrl, portalSettings.PortalId, true); DataCache.RemoveCache(string.Format(DataCache.TabUrlCacheKey, portalSettings.PortalId)); DataCache.ClearCache("url_CustomAliasList"); TabController.Instance.ClearCache(portalSettings.PortalId); return(new PageUrlResult { Success = true }); }
public void SaveTabUrl(TabUrlInfo tabUrl, int portalId, bool clearCache) { var portalAliasId = (tabUrl.PortalAliasUsage == PortalAliasUsageType.Default) ? Null.NullInteger : tabUrl.PortalAliasId; DataProvider.Instance().SaveTabUrl(tabUrl.TabId, tabUrl.SeqNum, portalAliasId, (int)tabUrl.PortalAliasUsage, tabUrl.Url, tabUrl.QueryString, tabUrl.CultureCode, tabUrl.HttpStatus, tabUrl.IsSystem); if (clearCache) { DataCache.RemoveCache(String.Format(DataCache.TabUrlCacheKey, portalId)); _legacyController.ClearCache(portalId); var tab = GetTab(tabUrl.TabId, portalId); tab.ClearTabUrls(); } }
public void DeleteTabUrl(TabUrlInfo tabUrl, int portalId, bool clearCache) { DataProvider.Instance().DeleteTabUrl(tabUrl.TabId, tabUrl.SeqNum); var objEventLog = new EventLogController(); objEventLog.AddLog("tabUrl.TabId", tabUrl.TabId.ToString(), PortalController.GetCurrentPortalSettings(), UserController.GetCurrentUserInfo().UserID, EventLogController.EventLogType.TABURL_DELETED); if (clearCache) { DataCache.RemoveCache(String.Format(DataCache.TabUrlCacheKey, portalId)); var tab = GetTab(tabUrl.TabId, portalId); tab.ClearTabUrls(); } }
protected void gvCustomUrls_ItemDataBound(object sender, GridItemEventArgs e) { if (e.Item is GridDataItem && (e.Item.DataItem.GetType() != typeof(GridInsertionObject))) { GridDataItem dataItem = (GridDataItem)e.Item; TabUrlInfo item = (TabUrlInfo)dataItem.DataItem; DropDownList ddlPortalAliasId = (DropDownList)dataItem.FindControl("ddlPortalAliasId"); DropDownList ddlPortalAliasUage = (DropDownList)dataItem.FindControl("ddlPortalAliasUsage"); DropDownList ddlHttpStatus = (DropDownList)dataItem.FindControl("ddlHttpStatus"); if (ddlPortalAliasId != null) { ListItem liPortalAliasId = ddlPortalAliasId.Items.FindByValue(item.PortalAliasId.ToString()); if (liPortalAliasId != null) { ddlPortalAliasId.ClearSelection(); liPortalAliasId.Selected = true; } } if (ddlPortalAliasUage != null) { int portalAliasUage = (int)item.PortalAliasUsage; ListItem liPortalAliasUage = ddlPortalAliasUage.Items.FindByValue(portalAliasUage.ToString()); if (liPortalAliasUage != null) { ddlPortalAliasUage.ClearSelection(); liPortalAliasUage.Selected = true; } } if (ddlHttpStatus != null) { ListItem liHttpStatus = ddlHttpStatus.Items.FindByValue(item.HttpStatus); if (liHttpStatus != null) { ddlHttpStatus.ClearSelection(); liHttpStatus.Selected = true; } } } }
public void SaveTabUrl(TabUrlInfo tabUrl, int portalId, bool clearCache) { var portalAliasId = (tabUrl.PortalAliasUsage == PortalAliasUsageType.Default) ? Null.NullInteger : tabUrl.PortalAliasId; var saveLog = EventLogController.EventLogType.TABURL_CREATED; if (tabUrl.HttpStatus == "200") { saveLog = EventLogController.EventLogType.TABURL_CREATED; } else { //need to see if sequence number exists to decide if insert or update List <TabUrlInfo> t = GetTabUrls(portalId, tabUrl.TabId); var existingSeq = t.FirstOrDefault(r => r.SeqNum == tabUrl.SeqNum); if (existingSeq == null) { saveLog = EventLogController.EventLogType.TABURL_CREATED; } } DataProvider.Instance().SaveTabUrl(tabUrl.TabId, tabUrl.SeqNum, portalAliasId, (int)tabUrl.PortalAliasUsage, tabUrl.Url, tabUrl.QueryString, tabUrl.CultureCode, tabUrl.HttpStatus, tabUrl.IsSystem, UserController.GetCurrentUserInfo().UserID); var objEventLog = new EventLogController(); objEventLog.AddLog("tabUrl", tabUrl.ToString(), PortalController.GetCurrentPortalSettings(), UserController.GetCurrentUserInfo().UserID, saveLog); if (clearCache) { DataCache.RemoveCache(String.Format(DataCache.TabUrlCacheKey, portalId)); CacheController.ClearCustomAliasesCache(); _legacyController.ClearCache(portalId); var tab = GetTab(tabUrl.TabId, portalId); tab.ClearTabUrls(); } }
public static void SaveTabUrl(TabUrlInfo tabUrl, int portalId, bool clearCache) { //var portalAliasId = (tabUrl.PortalAliasUsage == PortalAliasUsageType.Default) ? Null.NullInteger : tabUrl.PortalAliasId; int portalAliasId = tabUrl.PortalAliasId; if (portalAliasId > 0) { tabUrl.CultureCode = PortalAliasController.Instance.GetPortalAliasByPortalAliasID(portalAliasId).CultureCode; } EventLogController.EventLogType saveLog = EventLogController.EventLogType.TABURL_CREATED; if (tabUrl.HttpStatus == "200") { saveLog = EventLogController.EventLogType.TABURL_CREATED; } else { //need to see if sequence number exists to decide if insert or update List <TabUrlInfo> t = TabController.Instance.GetTabUrls(portalId, tabUrl.TabId); TabUrlInfo existingSeq = t.FirstOrDefault(r => r.SeqNum == tabUrl.SeqNum); if (existingSeq == null) { saveLog = EventLogController.EventLogType.TABURL_CREATED; } } DataProvider.Instance().SaveTabUrl(tabUrl.TabId, tabUrl.SeqNum, portalAliasId, (int)tabUrl.PortalAliasUsage, tabUrl.Url, tabUrl.QueryString, tabUrl.CultureCode, tabUrl.HttpStatus, tabUrl.IsSystem, UserController.Instance.GetCurrentUserInfo().UserID); EventLogController.Instance.AddLog("tabUrl", tabUrl.ToString(), PortalController.Instance.GetCurrentSettings() as IPortalSettings, UserController.Instance.GetCurrentUserInfo().UserID, saveLog); if (clearCache) { DataCache.RemoveCache(string.Format(DataCache.TabUrlCacheKey, portalId)); TabController.Instance.ClearCache(portalId); } }
protected void gvCustomUrls_DeleteCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e) { try { int tabID = ddlPage.SelectedItemValueAsInt; int seqnum = (int)((GridDataItem)e.Item).GetDataKeyValue("SeqNum"); List <TabUrlInfo> tabUrls = DotNetNuke.Entities.Tabs.Internal.TestableTabController.Instance.GetTabUrls(tabID, PortalId); TabUrlInfo tabUrl = tabUrls.Where(i => i.SeqNum == seqnum).FirstOrDefault(); if (tabUrl != null) { DotNetNuke.Entities.Tabs.Internal.TestableTabController.Instance.DeleteTabUrl(tabUrl, PortalId, true); } gvCustomUrls.Rebind(); } catch (Exception exc) { Exceptions.ProcessModuleLoadException(this, exc); } }
protected void gvCustomUrls_UpdateCommand(object sender, GridCommandEventArgs e) { GridEditableItem editedItem = e.Item as GridEditableItem; var SeqNum = (int)editedItem.GetDataKeyValue("SeqNum"); DropDownList ddlPortalAliasId = editedItem.FindControl("ddlPortalAliasId") as DropDownList; DropDownList ddlPortalAliasUsage = editedItem.FindControl("ddlPortalAliasUsage") as DropDownList; DropDownList ddlHttpStatus = editedItem.FindControl("ddlHttpStatus") as DropDownList; List <TabUrlInfo> tabUrls = DotNetNuke.Entities.Tabs.TabController.Instance.GetTabUrls(ddlPage.SelectedItemValueAsInt, PortalId); TabUrlInfo tabUrl = tabUrls.Where(i => i.SeqNum == SeqNum).FirstOrDefault(); Hashtable ht = new Hashtable(); editedItem.ExtractValues(ht); if (!string.IsNullOrEmpty(ddlPortalAliasId.SelectedValue)) { tabUrl.PortalAliasId = int.Parse(ddlPortalAliasId.SelectedValue); } if (!string.IsNullOrWhiteSpace(ddlPortalAliasUsage.SelectedValue)) { tabUrl.PortalAliasUsage = (PortalAliasUsageType)Enum.Parse(typeof(PortalAliasUsageType), ddlPortalAliasUsage.SelectedValue); } if (ht["Url"] != null) { tabUrl.Url = FriendlyUrlController.EnsureLeadingChar("/", ht["Url"].ToString()); } if (ht["QueryString"] != null) { tabUrl.QueryString = ht["QueryString"].ToString(); } tabUrl.HttpStatus = ddlHttpStatus.SelectedValue; DotNetNuke.Entities.Tabs.TabController.Instance.SaveTabUrl(tabUrl, PortalId, true); DotNetNuke.Common.Utilities.DataCache.ClearCache(); }
public void SaveTabUrl(TabUrlInfo tabUrl, int portalId, bool clearCache) { TabController.Instance.SaveTabUrl(tabUrl, portalId, clearCache); }
public PageUrlResult UpdateCustomUrl(SaveUrlDto dto, TabInfo tab) { var portalSettings = PortalController.Instance.GetCurrentPortalSettings(); var urlPath = dto.Path.ValueOrEmpty().TrimStart('/'); bool modified; //Clean Url var options = UrlRewriterUtils.ExtendOptionsForCustomURLs( UrlRewriterUtils.GetOptionsFromSettings(new FriendlyUrlSettings(portalSettings.PortalId))); //now clean the path urlPath = FriendlyUrlController.CleanNameForUrl(urlPath, options, out modified); if (modified) { return(new PageUrlResult { Success = false, ErrorMessage = Localization.GetString("CustomUrlPathCleaned.Error"), SuggestedUrlPath = "/" + urlPath }); } //Validate for uniqueness urlPath = FriendlyUrlController.ValidateUrl(urlPath, tab.TabID, portalSettings, out modified); if (modified) { return(new PageUrlResult { Success = false, ErrorMessage = Localization.GetString("UrlPathNotUnique.Error"), SuggestedUrlPath = "/" + urlPath }); } var cultureCode = LocaleController.Instance.GetLocales(portalSettings.PortalId) .Where(l => l.Value.KeyID == dto.LocaleKey) .Select(l => l.Value.Code) .SingleOrDefault() ?? portalSettings.DefaultLanguage; var statusCodeKey = dto.StatusCodeKey.ToString(CultureInfo.InvariantCulture); var tabUrl = tab.TabUrls.SingleOrDefault(t => t.SeqNum == dto.Id && t.HttpStatus == statusCodeKey); if (statusCodeKey == "200") { //We need to check if we are updating a current url or creating a new 200 if (tabUrl == null) { //Just create Url tabUrl = new TabUrlInfo { TabId = tab.TabID, SeqNum = dto.Id, PortalAliasId = dto.SiteAliasKey, PortalAliasUsage = (PortalAliasUsageType)dto.SiteAliasUsage, QueryString = dto.QueryString.ValueOrEmpty(), Url = dto.Path.ValueOrEmpty(), CultureCode = cultureCode, HttpStatus = "200", IsSystem = dto.IsSystem // false }; TabController.Instance.SaveTabUrl(tabUrl, portalSettings.PortalId, true); } else { if (!tabUrl.Url.Equals("/" + urlPath, StringComparison.InvariantCultureIgnoreCase)) { //Change the original 200 url to a redirect tabUrl.HttpStatus = "301"; tabUrl.SeqNum = dto.Id; TabController.Instance.SaveTabUrl(tabUrl, portalSettings.PortalId, true); //Add new custom url tabUrl.Url = dto.Path.ValueOrEmpty(); tabUrl.HttpStatus = "200"; tabUrl.SeqNum = tab.TabUrls.Max(t => t.SeqNum) + 1; tabUrl.CultureCode = cultureCode; tabUrl.PortalAliasId = dto.SiteAliasKey; tabUrl.PortalAliasUsage = (PortalAliasUsageType)dto.SiteAliasUsage; tabUrl.QueryString = dto.QueryString.ValueOrEmpty(); TabController.Instance.SaveTabUrl(tabUrl, portalSettings.PortalId, true); } else { //Update the original 200 url tabUrl.CultureCode = cultureCode; tabUrl.PortalAliasId = dto.SiteAliasKey; tabUrl.PortalAliasUsage = (PortalAliasUsageType)dto.SiteAliasUsage; tabUrl.QueryString = dto.QueryString.ValueOrEmpty(); TabController.Instance.SaveTabUrl(tabUrl, portalSettings.PortalId, true); } } } else { //Update the original non 200 url if (tabUrl == null) { tabUrl = new TabUrlInfo { TabId = tab.TabID, SeqNum = dto.Id, PortalAliasId = dto.SiteAliasKey, PortalAliasUsage = (PortalAliasUsageType)dto.SiteAliasUsage, QueryString = dto.QueryString.ValueOrEmpty(), Url = dto.Path.ValueOrEmpty(), CultureCode = cultureCode, HttpStatus = statusCodeKey, IsSystem = dto.IsSystem // false }; TabController.Instance.SaveTabUrl(tabUrl, portalSettings.PortalId, true); } else { tabUrl.CultureCode = cultureCode; tabUrl.PortalAliasId = dto.SiteAliasKey; tabUrl.PortalAliasUsage = (PortalAliasUsageType)dto.SiteAliasUsage; tabUrl.Url = dto.Path.ValueOrEmpty(); tabUrl.HttpStatus = statusCodeKey; tabUrl.QueryString = dto.QueryString.ValueOrEmpty(); TabController.Instance.SaveTabUrl(tabUrl, portalSettings.PortalId, true); } } return(new PageUrlResult { Success = true }); }
private Outcome UpdateTabUrl(TabInfo tab, int portalId, string fieldValue) { var portalSettings = new PortalSettings(portalId); var urlPath = fieldValue.ValueOrEmpty().TrimStart('/'); bool modified; // Clean Url var options = UrlRewriterUtils.ExtendOptionsForCustomURLs(UrlRewriterUtils.GetOptionsFromSettings(new FriendlyUrlSettings(portalSettings.PortalId))); urlPath = FriendlyUrlController.CleanNameForUrl(urlPath, options, out modified); if (modified) { return(new Outcome() { Success = false, ErrorMessage = Constants.ERROR_PAGE_URL_VALUE, //CustomUrlPathCleaned Suggestion = string.Concat(Constants.SLASH, urlPath) }); } // Validate for uniqueness urlPath = FriendlyUrlController.ValidateUrl(urlPath, -1, portalSettings, out modified); if (modified) { return(new Outcome() { Success = false, ErrorMessage = Constants.ERROR_PAGE_URL_NOT_UNIQUE, //UrlPathNotUnique Suggestion = string.Concat(Constants.SLASH, urlPath) }); } if (tab.TabUrls.Any(u => u.Url.ToLowerInvariant() == urlPath.ValueOrEmpty().ToLowerInvariant() && (u.PortalAliasId == portalSettings.PrimaryAlias.PortalAliasID || u.PortalAliasId == -1))) { return(new Outcome { Success = false, ErrorMessage = Constants.ERROR_PAGE_URL_DUPLICATE, //DuplicateUrl Suggestion = string.Concat(Constants.SLASH, urlPath) }); } var seqNum = (tab.TabUrls.Count > 0) ? tab.TabUrls.Max(t => t.SeqNum) + 1 : 1; var tabUrl = new TabUrlInfo { TabId = tab.TabID, SeqNum = seqNum, PortalAliasId = portalSettings.PrimaryAlias.PortalAliasID, PortalAliasUsage = PortalAliasUsageType.Default, QueryString = string.Empty, Url = urlPath.ValueOrEmpty(), CultureCode = portalSettings.CultureCode, HttpStatus = Constants.RESPONSE_STATUS_200, IsSystem = false, }; TabController.Instance.SaveTabUrl(tabUrl, portalSettings.PortalId, true); //tab.Url = fieldValue; return(new Outcome { Success = true, ErrorMessage = string.Empty, Suggestion = string.Empty }); }
public PageUrlResult CreateCustomUrl(SaveUrlDto dto, TabInfo tab) { var portalSettings = PortalController.Instance.GetCurrentPortalSettings(); var urlPath = dto.Path.ValueOrEmpty().TrimStart('/'); bool modified; //Clean Url var options = UrlRewriterUtils.ExtendOptionsForCustomURLs(UrlRewriterUtils.GetOptionsFromSettings(new FriendlyUrlSettings(portalSettings.PortalId))); urlPath = FriendlyUrlController.CleanNameForUrl(urlPath, options, out modified); if (modified) { return(new PageUrlResult { Success = false, ErrorMessage = Localization.GetString("CustomUrlPathCleaned.Error"), SuggestedUrlPath = "/" + urlPath }); } //Validate for uniqueness urlPath = FriendlyUrlController.ValidateUrl(urlPath, -1, portalSettings, out modified); if (modified) { return(new PageUrlResult { Success = false, ErrorMessage = Localization.GetString("UrlPathNotUnique.Error"), SuggestedUrlPath = "/" + urlPath }); } if (tab.TabUrls.Any(u => u.Url.ToLowerInvariant() == dto.Path.ValueOrEmpty().ToLowerInvariant() && (u.PortalAliasId == dto.SiteAliasKey || u.PortalAliasId == -1))) { return(new PageUrlResult { Success = false, ErrorMessage = Localization.GetString("DuplicateUrl.Error") }); } var seqNum = (tab.TabUrls.Count > 0) ? tab.TabUrls.Max(t => t.SeqNum) + 1 : 1; var portalLocales = LocaleController.Instance.GetLocales(portalSettings.PortalId); var cultureCode = portalLocales.Where(l => l.Value.KeyID == dto.LocaleKey) .Select(l => l.Value.Code) .SingleOrDefault(); var portalAliasUsage = (PortalAliasUsageType)dto.SiteAliasUsage; if (portalAliasUsage == PortalAliasUsageType.Default) { var alias = PortalAliasController.Instance.GetPortalAliasesByPortalId(portalSettings.PortalId) .SingleOrDefault(a => a.PortalAliasID == dto.SiteAliasKey); if (string.IsNullOrEmpty(cultureCode) || alias == null) { return(new PageUrlResult { Success = false, ErrorMessage = Localization.GetString("InvalidRequest.Error") }); } } else { var cultureAlias = PortalAliasController.Instance.GetPortalAliasesByPortalId(portalSettings.PortalId) .FirstOrDefault(a => a.CultureCode == cultureCode); if (portalLocales.Count > 1 && !portalSettings.ContentLocalizationEnabled && (string.IsNullOrEmpty(cultureCode) || cultureAlias == null)) { return(new PageUrlResult { Success = false, ErrorMessage = Localization.GetString("InvalidRequest.Error") }); } } var tabUrl = new TabUrlInfo { TabId = tab.TabID, SeqNum = seqNum, PortalAliasId = dto.SiteAliasKey, PortalAliasUsage = portalAliasUsage, QueryString = dto.QueryString.ValueOrEmpty(), Url = dto.Path.ValueOrEmpty(), CultureCode = cultureCode, HttpStatus = dto.StatusCodeKey.ToString(CultureInfo.InvariantCulture), IsSystem = false }; TabController.Instance.SaveTabUrl(tabUrl, portalSettings.PortalId, true); return(new PageUrlResult { Success = true, Id = seqNum // returns Id of the created Url }); }
public void SaveTabUrl(TabInfo tab, PageSettings pageSettings) { if (!pageSettings.CustomUrlEnabled) { return; } if (tab.IsSuperTab) { return; } var url = pageSettings.Url; var tabUrl = tab.TabUrls.SingleOrDefault(t => t.IsSystem && t.HttpStatus == "200" && t.SeqNum == 0); var portalSettings = PortalController.Instance.GetCurrentPortalSettings(); if (!String.IsNullOrEmpty(url) && url != "/") { url = CleanTabUrl(url); string currentUrl = String.Empty; var friendlyUrlSettings = new FriendlyUrlSettings(portalSettings.PortalId); if (tab.TabID > -1) { var baseUrl = Globals.AddHTTP(portalSettings.PortalAlias.HTTPAlias) + "/Default.aspx?TabId=" + tab.TabID; var path = AdvancedFriendlyUrlProvider.ImprovedFriendlyUrl(tab, baseUrl, Globals.glbDefaultPage, portalSettings.PortalAlias.HTTPAlias, false, friendlyUrlSettings, Guid.Empty); currentUrl = path.Replace(Globals.AddHTTP(portalSettings.PortalAlias.HTTPAlias), ""); } if (url == currentUrl) { return; } if (tabUrl == null) { //Add new custom url tabUrl = new TabUrlInfo { TabId = tab.TabID, SeqNum = 0, PortalAliasId = -1, PortalAliasUsage = PortalAliasUsageType.Default, QueryString = String.Empty, Url = url, HttpStatus = "200", CultureCode = String.Empty, IsSystem = true }; //Save url _tabController.SaveTabUrl(tabUrl, portalSettings.PortalId, true); } else { //Change the original 200 url to a redirect tabUrl.HttpStatus = "301"; tabUrl.SeqNum = tab.TabUrls.Max(t => t.SeqNum) + 1; _tabController.SaveTabUrl(tabUrl, portalSettings.PortalId, true); //Add new custom url tabUrl.Url = url; tabUrl.HttpStatus = "200"; tabUrl.SeqNum = 0; _tabController.SaveTabUrl(tabUrl, portalSettings.PortalId, true); } //Delete any redirects to the same url foreach (var redirecturl in _tabController.GetTabUrls(tab.TabID, tab.PortalID)) { if (redirecturl.Url == url && redirecturl.HttpStatus != "200") { _tabController.DeleteTabUrl(redirecturl, tab.PortalID, true); } } } else { if (url == "/" && tabUrl != null) { _tabController.DeleteTabUrl(tabUrl, portalSettings.PortalId, true); } } }
public void SaveTabUrl(TabUrlInfo tabUrl, int portalId, bool clearCache) { var portalAliasId = (tabUrl.PortalAliasUsage == PortalAliasUsageType.Default) ? Null.NullInteger : tabUrl.PortalAliasId; var saveLog = EventLogController.EventLogType.TABURL_CREATED; if (tabUrl.HttpStatus == "200") { saveLog = EventLogController.EventLogType.TABURL_CREATED; } else { //need to see if sequence number exists to decide if insert or update List<TabUrlInfo> t = GetTabUrls(portalId, tabUrl.TabId); var existingSeq = t.FirstOrDefault(r => r.SeqNum == tabUrl.SeqNum); if (existingSeq == null) { saveLog = EventLogController.EventLogType.TABURL_CREATED; } } DataProvider.Instance().SaveTabUrl(tabUrl.TabId, tabUrl.SeqNum, portalAliasId, (int)tabUrl.PortalAliasUsage, tabUrl.Url, tabUrl.QueryString, tabUrl.CultureCode, tabUrl.HttpStatus, tabUrl.IsSystem,UserController.GetCurrentUserInfo().UserID); var objEventLog = new EventLogController(); objEventLog.AddLog("tabUrl", tabUrl.ToString(), PortalController.GetCurrentPortalSettings(), UserController.GetCurrentUserInfo().UserID, saveLog); if (clearCache) { DataCache.RemoveCache(String.Format(DataCache.TabUrlCacheKey, portalId)); _legacyController.ClearCache(portalId); var tab = GetTab(tabUrl.TabId, portalId); tab.ClearTabUrls(); } }
public HttpResponseMessage UpdateCustomUrl(SaveUrlDto dto) { var tab = PortalSettings.ActiveTab; var urlPath = dto.Path.ValueOrEmpty().TrimStart('/'); HttpResponseMessage response; if (string.IsNullOrEmpty(urlPath)) { var tabUrl = new TabUrlInfo { TabId = tab.TabID, SeqNum = dto.Id, }; TestableTabController.Instance.DeleteTabUrl(tabUrl, PortalId, true); response = Request.CreateResponse(HttpStatusCode.OK, new { Success = true, }); } else { bool modified; //Clean Url var options = UrlRewriterUtils.GetOptionsFromSettings(new FriendlyUrlSettings(PortalSettings.PortalId)); //custom urls are special in that they can contain the / character to create path levels options.ReplaceChars = options.ReplaceChars.Replace("/", ""); options.IllegalChars = options.IllegalChars.Replace("/", ""); options.RegexMatch = options.RegexMatch.Replace("[^", "[^/"); //now clean the path urlPath = FriendlyUrlController.CleanNameForUrl(urlPath, options, out modified); if (modified) { return(Request.CreateResponse(HttpStatusCode.OK, new { Success = false, ErrorMessage = Localization.GetString("UrlPathCleaned.Error", Localization.GlobalResourceFile), SuggestedUrlPath = "/" + urlPath })); } //Validate for uniqueness urlPath = FriendlyUrlController.ValidateUrl(urlPath, -1, PortalSettings, out modified); if (modified) { return(Request.CreateResponse(HttpStatusCode.OK, new { Success = false, ErrorMessage = Localization.GetString("UrlPathNotUnique.Error", Localization.GlobalResourceFile), SuggestedUrlPath = "/" + urlPath })); } var cultureCode = LocaleController.Instance.GetLocales(PortalId) .Where(l => l.Value.KeyID == dto.LocaleKey) .Select(l => l.Value.Code) .SingleOrDefault(); var tabUrl = new TabUrlInfo { TabId = tab.TabID, SeqNum = dto.Id, PortalAliasId = dto.SiteAliasKey, PortalAliasUsage = (PortalAliasUsageType)dto.SiteAliasUsage, QueryString = dto.QueryString.ValueOrEmpty(), Url = dto.Path.ValueOrEmpty(), CultureCode = cultureCode, HttpStatus = dto.StatusCodeKey.ToString(CultureInfo.InvariantCulture), IsSystem = dto.IsSystem // false }; TestableTabController.Instance.SaveTabUrl(tabUrl, PortalId, true); response = Request.CreateResponse(HttpStatusCode.OK, new { Success = true, }); } return(response); }
public HttpResponseMessage UpdateCustomUrl(SaveUrlDto dto) { var urlPath = dto.Path.ValueOrEmpty().TrimStart('/'); bool modified; //Clean Url var options = UrlRewriterUtils.ExtendOptionsForCustomURLs(UrlRewriterUtils.GetOptionsFromSettings(new FriendlyUrlSettings(PortalSettings.PortalId))); //now clean the path urlPath = FriendlyUrlController.CleanNameForUrl(urlPath, options, out modified); if (modified) { return(Request.CreateResponse(HttpStatusCode.OK, new { Success = false, ErrorMessage = Localization.GetString("CustomUrlPathCleaned.Error", Localization.GlobalResourceFile), SuggestedUrlPath = "/" + urlPath })); } //Validate for uniqueness urlPath = FriendlyUrlController.ValidateUrl(urlPath, -1, PortalSettings, out modified); if (modified) { return(Request.CreateResponse(HttpStatusCode.OK, new { Success = false, ErrorMessage = Localization.GetString("UrlPathNotUnique.Error", Localization.GlobalResourceFile), SuggestedUrlPath = "/" + urlPath })); } var tab = PortalSettings.ActiveTab; var cultureCode = LocaleController.Instance.GetLocales(PortalId) .Where(l => l.Value.KeyID == dto.LocaleKey) .Select(l => l.Value.Code) .SingleOrDefault(); if (dto.StatusCodeKey.ToString(CultureInfo.InvariantCulture) == "200") { //We need to check if we are updating a current url or creating a new 200 var tabUrl = tab.TabUrls.SingleOrDefault(t => t.SeqNum == dto.Id && t.HttpStatus == "200"); if (tabUrl == null) { //Just create Url tabUrl = new TabUrlInfo { TabId = tab.TabID, SeqNum = dto.Id, PortalAliasId = dto.SiteAliasKey, PortalAliasUsage = (PortalAliasUsageType)dto.SiteAliasUsage, QueryString = dto.QueryString.ValueOrEmpty(), Url = dto.Path.ValueOrEmpty(), CultureCode = cultureCode, HttpStatus = dto.StatusCodeKey.ToString(CultureInfo.InvariantCulture), IsSystem = dto.IsSystem // false }; TabController.Instance.SaveTabUrl(tabUrl, PortalId, true); } else { //Change the original 200 url to a redirect tabUrl.HttpStatus = "301"; tabUrl.SeqNum = dto.Id; TabController.Instance.SaveTabUrl(tabUrl, PortalId, true); //Add new custom url tabUrl.Url = dto.Path.ValueOrEmpty(); tabUrl.HttpStatus = "200"; tabUrl.SeqNum = tab.TabUrls.Max(t => t.SeqNum) + 1; TabController.Instance.SaveTabUrl(tabUrl, PortalId, true); } } else { //Just update the url var tabUrl = new TabUrlInfo { TabId = tab.TabID, SeqNum = dto.Id, PortalAliasId = dto.SiteAliasKey, PortalAliasUsage = (PortalAliasUsageType)dto.SiteAliasUsage, QueryString = dto.QueryString.ValueOrEmpty(), Url = dto.Path.ValueOrEmpty(), CultureCode = cultureCode, HttpStatus = dto.StatusCodeKey.ToString(CultureInfo.InvariantCulture), IsSystem = dto.IsSystem // false }; TabController.Instance.SaveTabUrl(tabUrl, PortalId, true); } var response = new { Success = true, }; return(Request.CreateResponse(HttpStatusCode.OK, response)); }