/// <summary> /// /// </summary> /// <param name="portalSettings"></param> /// <returns></returns> public static TabInfo GetTabFromUrl(PortalSettings portalSettings) { var tc = new TabController(); TabInfo tInfo = null; var url = HttpContext.Current.Request.Url.AbsoluteUri.Replace("?" + HttpContext.Current.Request.QueryString, "").Replace("http://", "").Replace("https://", "").Replace(portalSettings.PortalAlias.HTTPAlias,"").ToLower(); try { int tabId; if (url.Contains("tabid")) { tabId = Int32.Parse(Regex.Match(url, "tabid[=/](\\d+)", RegexOptions.IgnoreCase).Groups[1].Value); tInfo = tc.GetTab(tabId, portalSettings.PortalId, false); } else { string strippedUrl = url; do { tabId = TabController.GetTabByTabPath(portalSettings.PortalId, strippedUrl.Replace("/", "//").Replace("-", ""), portalSettings.CultureCode); if (tabId != -1) { tInfo = tc.GetTab(tabId, portalSettings.PortalId, false); break; } var slashIndex = strippedUrl.LastIndexOf('/'); strippedUrl = slashIndex > 1 ? strippedUrl.Substring(0, slashIndex) : ""; } while (strippedUrl.Length > 0); //if (url.Contains("/" + GetQuestionUrlName(portalSettings).ToLower() + "/")) //{ // var tabPath = url.Substring(0, url.IndexOf("/" + GetQuestionUrlName(portalSettings).ToLower() + "/")); // //TODO JS: The - replacement needs to be more generic. // tabPath = tabPath.Replace("/", "//").Replace("-",""); // tabId = TabController.GetTabByTabPath(portalSettings.PortalId, tabPath, portalSettings.CultureCode); // tInfo = tc.GetTab(tabId, portalSettings.PortalId, false); //} //else //{ // if (url.Contains("/" + GetTagUrlName().ToLower() + "/")) // { // var tabPath = url.Substring(0, url.IndexOf("/" + GetTagUrlName().ToLower() + "/")); // tabPath = tabPath.Replace("/", "//").Replace("-", ""); // tabId = TabController.GetTabByTabPath(portalSettings.PortalId, tabPath, portalSettings.CultureCode); // tInfo = tc.GetTab(tabId, portalSettings.PortalId, false); // } //} } } catch (Exception ex) { DotNetNuke.Services.Exceptions.Exceptions.LogException(ex); } if (tInfo == null) { var lc = new DotNetNuke.Services.Log.EventLog.LogController(); var logInfo = new DotNetNuke.Services.Log.EventLog.LogInfo { LogTypeKey = "ADMIN_ALERT", LogPortalID = portalSettings.PortalId }; logInfo.AddProperty("DNNQA HTTP Module", "GetTabFromURL returned null. URL=" + url); lc.AddLog(logInfo); } return tInfo; }
/// <summary> /// /// </summary> /// <param name="portalSettings"></param> /// <returns></returns> public static TabInfo GetTabFromUrl(PortalSettings portalSettings) { var tc = new TabController(); TabInfo tInfo = null; var url = HttpContext.Current.Request.Url.AbsoluteUri.Replace("?" + HttpContext.Current.Request.QueryString, "").Replace("http://", "").Replace("https://", "").Replace(portalSettings.PortalAlias.HTTPAlias, "").ToLower(); try { int tabId; if (url.Contains("tabid")) { tabId = Int32.Parse(Regex.Match(url, "tabid[=/](\\d+)", RegexOptions.IgnoreCase).Groups[1].Value); tInfo = tc.GetTab(tabId, portalSettings.PortalId, false); } else { string strippedUrl = url; do { tabId = TabController.GetTabByTabPath(portalSettings.PortalId, strippedUrl.Replace("/", "//").Replace("-", ""), portalSettings.CultureCode); if (tabId != -1) { tInfo = tc.GetTab(tabId, portalSettings.PortalId, false); break; } var slashIndex = strippedUrl.LastIndexOf('/'); strippedUrl = slashIndex > 1 ? strippedUrl.Substring(0, slashIndex) : ""; } while (strippedUrl.Length > 0); //if (url.Contains("/" + GetQuestionUrlName(portalSettings).ToLower() + "/")) //{ // var tabPath = url.Substring(0, url.IndexOf("/" + GetQuestionUrlName(portalSettings).ToLower() + "/")); // //TODO JS: The - replacement needs to be more generic. // tabPath = tabPath.Replace("/", "//").Replace("-",""); // tabId = TabController.GetTabByTabPath(portalSettings.PortalId, tabPath, portalSettings.CultureCode); // tInfo = tc.GetTab(tabId, portalSettings.PortalId, false); //} //else //{ // if (url.Contains("/" + GetTagUrlName().ToLower() + "/")) // { // var tabPath = url.Substring(0, url.IndexOf("/" + GetTagUrlName().ToLower() + "/")); // tabPath = tabPath.Replace("/", "//").Replace("-", ""); // tabId = TabController.GetTabByTabPath(portalSettings.PortalId, tabPath, portalSettings.CultureCode); // tInfo = tc.GetTab(tabId, portalSettings.PortalId, false); // } //} } } catch (Exception ex) { DotNetNuke.Services.Exceptions.Exceptions.LogException(ex); } if (tInfo == null) { var lc = new DotNetNuke.Services.Log.EventLog.LogController(); var logInfo = new DotNetNuke.Services.Log.EventLog.LogInfo { LogTypeKey = "ADMIN_ALERT", LogPortalID = portalSettings.PortalId }; logInfo.AddProperty("DNNQA HTTP Module", "GetTabFromURL returned null. URL=" + url); lc.AddLog(logInfo); } return(tInfo); }