public override void TestFixtureSetUp() { base.TestFixtureSetUp(); var tc = new TabController(); var tab = tc.GetTabByName(_aboutUsPageName, PortalId); _tabId = tab.TabID; //Add Portal Aliases var aliasController = new PortalAliasController(); TestUtil.ReadStream(String.Format("{0}", "Aliases"), (line, header) => { string[] fields = line.Split(','); var alias = aliasController.GetPortalAlias(fields[0], PortalId); if (alias == null) { alias = new PortalAliasInfo { HTTPAlias = fields[0], PortalID = PortalId }; TestablePortalAliasController.Instance.AddPortalAlias(alias); } }); TestUtil.ReadStream(String.Format("{0}", "Users"), (line, header) => { string[] fields = line.Split(','); TestUtil.AddUser(PortalId, fields[0].Trim(), fields[1].Trim(), fields[2].Trim()); }); }
public override void TestFixtureTearDown() { base.TestFixtureTearDown(); var aliasController = new PortalAliasController(); TestUtil.ReadStream(String.Format("{0}", "Aliases"), (line, header) => { string[] fields = line.Split(','); var alias = aliasController.GetPortalAlias(fields[0], PortalId); TestablePortalAliasController.Instance.DeletePortalAlias(alias); }); TestUtil.ReadStream(String.Format("{0}", "Users"), (line, header) => { string[] fields = line.Split(','); TestUtil.DeleteUser(PortalId, fields[0]); }); }
private static void Handle404OrException(FriendlyUrlSettings settings, HttpContext context, Exception ex, UrlAction result, bool transfer, bool showDebug) { //handle Auto-Add Alias if (result.Action == ActionType.Output404 && CanAutoAddPortalAlias()) { //Need to determine if this is a real 404 or a possible new alias. var portalId = Host.Host.HostPortalID; if (portalId > Null.NullInteger) { //Get all the existing aliases var aliases = TestablePortalAliasController.Instance.GetPortalAliasesByPortalId(portalId).ToList(); bool autoaddAlias; bool isPrimary = false; if (!aliases.Any()) { autoaddAlias = true; isPrimary = true; } else { autoaddAlias = true; foreach (var alias in aliases) { if (result.DomainName.ToLowerInvariant().IndexOf(alias.HTTPAlias, StringComparison.Ordinal) == 0 && result.DomainName.Length >= alias.HTTPAlias.Length) { autoaddAlias = false; break; } } } if (autoaddAlias) { var portalAliasInfo = new PortalAliasInfo { PortalID = portalId, HTTPAlias = result.RewritePath, IsPrimary = isPrimary }; TestablePortalAliasController.Instance.AddPortalAlias(portalAliasInfo); context.Response.Redirect(context.Request.Url.ToString(), true); } } } if (context != null) { HttpRequest request = context.Request; HttpResponse response = context.Response; HttpServerUtility server = context.Server; const string errorPageHtmlHeader = @"<html><head><title>{0}</title></head><body>"; const string errorPageHtmlFooter = @"</body></html>"; var errorPageHtml = new StringWriter(); CustomErrorsSection ceSection = null; //876 : security catch for custom error reading try { ceSection = (CustomErrorsSection) WebConfigurationManager.GetSection("system.web/customErrors"); } // ReSharper disable EmptyGeneralCatchClause catch (Exception) // ReSharper restore EmptyGeneralCatchClause { //on some medium trust environments, this will throw an exception for trying to read the custom Errors //do nothing } /* 454 new 404/500 error handling routine */ bool useDNNTab = false; int errTabId = -1; string errUrl = null; string status = ""; bool isPostback = false; if (settings != null) { if (request.RequestType == "POST") { isPostback = true; } if (result != null && ex != null) { result.DebugMessages.Add("Exception: " + ex.Message); result.DebugMessages.Add("Stack Trace: " + ex.StackTrace); if (ex.InnerException != null) { result.DebugMessages.Add("Inner Ex : " + ex.InnerException.Message); result.DebugMessages.Add("Stack Trace: " + ex.InnerException.StackTrace); } else { result.DebugMessages.Add("Inner Ex : null"); } } string errRH; string errRV; int statusCode; if (result != null && result.Action != ActionType.Output404) { //output everything but 404 (usually 500) if (settings.TabId500 > -1) //tabid specified for 500 error page, use that { useDNNTab = true; errTabId = settings.TabId500; } errUrl = settings.Url500; errRH = "X-UrlRewriter-500"; errRV = "500 Rewritten to {0} : {1}"; statusCode = 500; status = "500 Internal Server Error"; } else //output 404 error { if (settings.TabId404 > -1) //if the tabid is specified for a 404 page, then use that { useDNNTab = true; errTabId = settings.TabId404; } if (!String.IsNullOrEmpty(settings.Regex404)) //with 404 errors, there's an option to catch certain urls and use an external url for extra processing. { try { //944 : check the original Url in case the requested Url has been rewritten before discovering it's a 404 error string requestedUrl = request.Url.ToString(); if (result != null && string.IsNullOrEmpty(result.OriginalPath) == false) { requestedUrl = result.OriginalPath; } if (Regex.IsMatch(requestedUrl, settings.Regex404, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant)) { useDNNTab = false; //if we have a match in the 404 regex value, then don't use the tabid } } catch (Exception regexEx) { //.some type of exception : output in response header, and go back to using the tabid response.AppendHeader("X-UrlRewriter-404Exception", regexEx.Message); } } errUrl = settings.Url404; errRH = "X-UrlRewriter-404"; errRV = "404 Rewritten to {0} : {1} : Reason {2}"; status = "404 Not Found"; statusCode = 404; } // check for 404 logging if ((result == null || result.Action == ActionType.Output404)) { //Log 404 errors to Event Log UrlRewriterUtils.Log404(request, settings, result); } //912 : use unhandled 404 switch string reason404 = null; bool unhandled404 = true; if (useDNNTab && errTabId > -1) { unhandled404 = false; //we're handling it here var tc = new TabController(); TabInfo errTab = tc.GetTab(errTabId, result.PortalId, true); if (errTab != null) { bool redirect = false; //ok, valid tabid. what we're going to do is to load up this tab via a rewrite of the url, and then change the output status string reason = "Not Found"; if (result != null) { reason = result.Reason.ToString(); } response.AppendHeader(errRH, string.Format(errRV, "DNN Tab", errTab.TabName + "(Tabid:" + errTabId.ToString() + ")", reason)); //show debug messages even if in debug mode if (context != null && response != null && result != null && showDebug) { ShowDebugData(context, result.OriginalPath, result, null); } if (!isPostback) { response.ClearContent(); response.StatusCode = statusCode; response.Status = status; } else { redirect = true; //redirect postbacks as you can't postback successfully to a server.transfer } errUrl = Globals.glbDefaultPage + TabIndexController.CreateRewritePath(errTab.TabID, ""); //have to update the portal settings with the new tabid PortalSettings ps = null; if (context != null && context.Items != null) { if (context.Items.Contains("PortalSettings")) { ps = (PortalSettings) context.Items["PortalSettings"]; context.Items.Remove("PortalSettings"); //nix it from the context } } if (ps != null && ps.PortalAlias != null) { ps = new PortalSettings(errTabId, ps.PortalAlias); } else { if (result.HttpAlias != null && result.PortalId > -1) { var pac = new PortalAliasController(); PortalAliasInfo pa = pac.GetPortalAlias(result.HttpAlias, result.PortalId); ps = new PortalSettings(errTabId, pa); } else { //912 : handle 404 when no valid portal can be identified //results when iis is configured to handle portal alias, but //DNN isn't. This always returns 404 because a multi-portal site //can't just show the 404 page of the host site. var pc = new PortalController(); ArrayList portals = pc.GetPortals(); if (portals != null && portals.Count == 1) { //single portal install, load up portal settings for this portal var singlePortal = (PortalInfo) portals[0]; //list of aliases from database var aliases = TestablePortalAliasController.Instance.GetPortalAliasesByPortalId(singlePortal.PortalID).ToList(); //list of aliases from Advanced Url settings List<string> chosen = aliases.GetAliasesForPortalId(singlePortal.PortalID); PortalAliasInfo useFor404 = null; //go through all aliases and either get the first valid one, or the first //as chosen in the advanced url management settings foreach (var pa in aliases) { if (useFor404 == null) { useFor404 = pa; //first one by default } //matching? if (chosen != null && chosen.Count > 0) { if (chosen.Contains(pa.HTTPAlias)) { useFor404 = pa; } } else { break; //no further checking } } //now configure that as the portal settings if (useFor404 != null) { //create portal settings context for identified portal alias in single portal install ps = new PortalSettings(errTabId, useFor404); } } else { reason404 = "Requested domain name is not configured as valid website"; unhandled404 = true; } } } if (ps != null) { //re-add the context items portal settings back in context.Items.Add("PortalSettings", ps); } if (redirect) { errUrl = Globals.NavigateURL(); response.Redirect(errUrl, true); //redirect and end response. //It will mean the user will have to postback again, but it will work the second time } else { if (transfer) { //execute a server transfer to the default.aspx?tabid=xx url //767 : object not set error on extensionless 404 errors if (context.User == null) { context.User = Thread.CurrentPrincipal; } response.TrySkipIisCustomErrors = true; //881 : spoof the basePage object so that the client dependency framework //is satisfied it's working with a page-based handler IHttpHandler spoofPage = new CDefault(); context.Handler = spoofPage; server.Transfer("~/" + errUrl, true); } else { context.RewritePath("~/Default.aspx", false); response.TrySkipIisCustomErrors = true; response.Status = "404 Not Found"; response.StatusCode = 404; } } } } //912 : change to new if statement to handle cases where the TabId404 couldn't be handled correctly if (unhandled404) { //proces the error on the external Url by rewriting to the external url if (!String.IsNullOrEmpty(errUrl)) { response.ClearContent(); response.TrySkipIisCustomErrors = true; string reason = "Not Found"; if (result != null) { reason = result.Reason.ToString(); } response.AppendHeader(errRH, string.Format(errRV, "Url", errUrl, reason)); if (reason404 != null) { response.AppendHeader("X-Url-Master-404-Data", reason404); } response.StatusCode = statusCode; response.Status = status; server.Transfer("~/" + errUrl, true); } else { #if (DEBUG) //955: xss vulnerability when outputting raw url back to the page //only do so in debug mode, and sanitize the Url. //sanitize output Url to prevent xss attacks on the default 404 page string requestedUrl = request.Url.ToString(); requestedUrl = HttpUtility.HtmlEncode(requestedUrl); errorPageHtml.Write(status + "<br>The requested Url (" + requestedUrl + ") does not return any valid content."); #else errorPageHtml.Write(status + "<br>The requested Url does not return any valid content."); #endif if (reason404 != null) { errorPageHtml.Write(status + "<br>" + reason404); } errorPageHtml.Write("<div style='font-weight:bolder'>Administrators</div>"); errorPageHtml.Write("<div>Change this message by configuring a specific 404 Error Page or Url for this website.</div>"); //output a reason for the 404 string reason = ""; if (result != null) { reason = result.Reason.ToString(); } if (!string.IsNullOrEmpty(errRH) && !string.IsNullOrEmpty(reason)) { response.AppendHeader(errRH, reason); } response.StatusCode = statusCode; response.Status = status; } } } else { //fallback output if not valid settings if (result != null && result.Action == ActionType.Output404) { //don't restate the requested Url to prevent cross site scripting errorPageHtml.Write("404 Not Found<br>The requested Url does not return any valid content."); response.StatusCode = 404; response.Status = "404 Not Found"; } else { //error, especially if invalid result object errorPageHtml.Write("500 Server Error<br><div style='font-weight:bolder'>An error occured during processing : if possible, check the event log of the server</div>"); response.StatusCode = 500; response.Status = "500 Internal Server Error"; if (result != null) { result.Action = ActionType.Output500; } } } if (ex != null) { if (context != null) { if (context.Items.Contains("UrlRewrite:Exception") == false) { context.Items.Add("UrlRewrite:Exception", ex.Message); context.Items.Add("UrlRewrite:StackTrace", ex.StackTrace); } } if (ceSection != null && ceSection.Mode == CustomErrorsMode.Off) { errorPageHtml.Write(errorPageHtmlHeader); errorPageHtml.Write("<div style='font-weight:bolder'>Exception:</div><div>" + ex.Message + "</div>"); errorPageHtml.Write("<div style='font-weight:bolder'>Stack Trace:</div><div>" + ex.StackTrace + "</div>"); errorPageHtml.Write("<div style='font-weight:bolder'>Administrators</div>"); errorPageHtml.Write("<div>You can see this exception because the customErrors attribute in the web.config is set to 'off'. Change this value to 'on' or 'RemoteOnly' to show Error Handling</div>"); try { if (errUrl != null && errUrl.StartsWith("~")) { errUrl = VirtualPathUtility.ToAbsolute(errUrl); } } finally { if (errUrl != null) { errorPageHtml.Write("<div>The error handling would have shown this page : <a href='" + errUrl + "'>" + errUrl + "</a></div>"); } else { errorPageHtml.Write("<div>The error handling could not determine the correct page to show.</div>"); } } } } string errorPageHtmlBody = errorPageHtml.ToString(); if (errorPageHtmlBody.Length > 0) { response.Write(errorPageHtmlHeader); response.Write(errorPageHtmlBody); response.Write(errorPageHtmlFooter); } if (ex != null) { UrlRewriterUtils.LogExceptionInRequest(ex, status, result); } } }
private void IdentifyPortalAlias(HttpContext context, HttpRequest request, Uri requestUri, UrlAction result, NameValueCollection queryStringCol, FriendlyUrlSettings settings, Guid parentTraceId) { //get the domain name of the request, if it isn't already supplied if (request != null && string.IsNullOrEmpty(result.DomainName)) { result.DomainName = Globals.GetDomainName(request); //parse the domain name out of the request } // get tabId from querystring ( this is mandatory for maintaining portal context for child portals ) if (queryStringCol["tabid"] != null) { string raw = queryStringCol["tabid"]; int tabId; if (Int32.TryParse(raw, out tabId)) { result.TabId = tabId; } else { //couldn't parse tab id //split in two? string[] tabids = raw.Split(','); if (tabids.GetUpperBound(0) > 0) { //hmm more than one tabid if (Int32.TryParse(tabids[0], out tabId)) { result.TabId = tabId; //but we want to warn against this! var ex = new Exception( "Illegal request exception : Two TabId parameters provided in a single request: " + requestUri); UrlRewriterUtils.LogExceptionInRequest(ex, "Not Set", result); result.Ex = ex; } else { //yeah, nothing, divert to 404 result.Action = ActionType.Output404; var ex = new Exception( "Illegal request exception : TabId parameters in query string, but invalid TabId requested : " + requestUri); UrlRewriterUtils.LogExceptionInRequest(ex, "Not Set", result); result.Ex = ex; } } } } // get PortalId from querystring ( this is used for host menu options as well as child portal navigation ) if (queryStringCol["portalid"] != null) { string raw = queryStringCol["portalid"]; int portalId; if (Int32.TryParse(raw, out portalId)) { //848 : if portal already found is different to portal id in querystring, then load up different alias //this is so the portal settings will be loaded correctly. if (result.PortalId != portalId) { //portal id different to what we expected result.PortalId = portalId; //check the loaded portal alias, because it might be wrong if (result.PortalAlias != null && result.PortalAlias.PortalID != portalId) { //yes, the identified portal alias is wrong. Find the correct alias for this portal PortalAliasInfo pa = TabIndexController.GetPortalAliasByPortal(portalId, result.DomainName); if (pa != null) { //note: sets portal id and portal alias result.PortalAlias = pa; } } } } } else { //check for a portal alias if there's no portal Id in the query string //check for absence of captcha value, because the captcha string re-uses the alias querystring value if (queryStringCol["alias"] != null && queryStringCol["captcha"] == null) { string alias = queryStringCol["alias"]; PortalAliasInfo portalAlias = PortalAliasController.GetPortalAliasInfo(alias); if (portalAlias != null) { //ok the portal alias was found by the alias name // check if the alias contains the domain name if (alias.Contains(result.DomainName) == false) { // replaced to the domain defined in the alias if (request != null) { string redirectDomain = Globals.GetPortalDomainName(alias, request, true); //retVal.Url = redirectDomain; result.FinalUrl = redirectDomain; result.Action = ActionType.Redirect302Now; result.Reason = RedirectReason.Alias_In_Url; } } else { // the alias is the same as the current domain result.HttpAlias = portalAlias.HTTPAlias; result.PortalAlias = portalAlias; result.PortalId = portalAlias.PortalID; //don't use this crap though - we don't want ?alias=portalAlias in our Url if (result.RedirectAllowed) { string redirect = requestUri.Scheme + Uri.SchemeDelimiter + result.PortalAlias.HTTPAlias + "/"; result.Action = ActionType.Redirect301; result.FinalUrl = redirect; result.Reason = RedirectReason.Unfriendly_Url_Child_Portal; } } } } } //first try and identify the portal using the tabId, but only if we identified this tab by looking up the tabid //from the original url //668 : error in child portal redirects to child portal home page because of mismatch in tab/domain name if (result.TabId != -1 && result.FriendlyRewrite == false) { // get the alias from the tabid, but only if it is for a tab in that domain // 2.0 : change to compare retrieved alias to the already-set httpAlias string httpAliasFromTab = PortalAliasController.GetPortalAliasByTab(result.TabId, result.DomainName); if (httpAliasFromTab != null) { //882 : account for situation when portalAlias is null. if (result.PortalAlias != null && String.Compare(result.PortalAlias.HTTPAlias, httpAliasFromTab, StringComparison.OrdinalIgnoreCase) != 0 || result.PortalAlias == null) { //691 : change logic to force change in portal alias context rather than force back. //This is because the tabid in the query string should take precedence over the portal alias //to handle parent.com/default.aspx?tabid=xx where xx lives in parent.com/child/ var tc = new TabController(); var tab = tc.GetTab(result.TabId, Null.NullInteger, false); //when result alias is null or result alias is different from tab-identified portalAlias if (tab != null && (result.PortalAlias == null || tab.PortalID != result.PortalAlias.PortalID)) { //the tabid is different to the identified portalid from the original alias identified //so get a new alias var pac = new PortalAliasController(); PortalAliasInfo tabPortalAlias = pac.GetPortalAlias(httpAliasFromTab, tab.PortalID); if (tabPortalAlias != null) { result.PortalId = tabPortalAlias.PortalID; result.PortalAlias = tabPortalAlias; result.Action = ActionType.CheckFor301; result.Reason = RedirectReason.Wrong_Portal; } } } } } //if no alias, try and set by using the identified http alias or domain name if (result.PortalAlias == null) { if (!string.IsNullOrEmpty(result.HttpAlias)) { result.PortalAlias = PortalAliasController.GetPortalAliasInfo(result.HttpAlias); } else { result.PortalAlias = PortalAliasController.GetPortalAliasInfo(result.DomainName); if (result.PortalAlias == null && result.DomainName.EndsWith("/")) { result.DomainName = result.DomainName.TrimEnd('/'); result.PortalAlias = PortalAliasController.GetPortalAliasInfo(result.DomainName); } } } if (result.PortalId == -1) { if (!requestUri.LocalPath.ToLower().EndsWith(Globals.glbDefaultPage.ToLower())) { // allows requests for aspx pages in custom folder locations to be processed return; } //the domain name was not found so try using the host portal's first alias if (Host.Host.HostPortalID != -1) { result.PortalId = Host.Host.HostPortalID; // use the host portal, but replaced to the host portal home page var aliases = TestablePortalAliasController.Instance.GetPortalAliasesByPortalId(result.PortalId).ToList(); if (aliases.Count > 0) { string alias = null; //get the alias as the chosen portal alias for the host portal based on the result culture code var cpa = aliases.GetAliasByPortalIdAndSettings(result.PortalId, result, result.CultureCode, settings); if (cpa != null) { alias = cpa.HTTPAlias; } if (alias != null) { result.Action = ActionType.Redirect301; result.Reason = RedirectReason.Host_Portal_Used; string destUrl = MakeUrlWithAlias(requestUri, alias); destUrl = CheckForSiteRootRedirect(alias, destUrl); result.FinalUrl = destUrl; } else { //Get the first Alias for the host portal result.PortalAlias = aliases[result.PortalId]; string url = MakeUrlWithAlias(requestUri, result.PortalAlias); if (result.TabId != -1) { url += requestUri.Query; } result.FinalUrl = url; result.Reason = RedirectReason.Host_Portal_Used; result.Action = ActionType.Redirect302Now; } } } } //double check to make sure we still have the correct alias now that all other information is known (ie tab, portal, culture) //770 : redirect alias based on tab id when custom alias used if (result.TabId == -1 && result.Action == ActionType.CheckFor301 && result.Reason == RedirectReason.Custom_Tab_Alias) { //here because the portal alias matched, but no tab was found, and because there are custom tab aliases used for this portal //need to redirect back to the chosen portal alias and keep the current path. string wrongAlias = result.HttpAlias; //it's a valid alias, but only for certain tabs var primaryAliases = TestablePortalAliasController.Instance.GetPortalAliasesByPortalId(result.PortalId).ToList(); if (primaryAliases != null && result.PortalId > -1) { //going to look for the correct alias based on the culture of the request string requestCultureCode = result.CultureCode; //if that didn't work use the default language of the portal if (requestCultureCode == null) { //this might end up in a double redirect if the path of the Url is for a specific language as opposed //to a path belonging to the default language domain var pc = new PortalController(); PortalInfo portal = pc.GetPortal(result.PortalId); if (portal != null) { requestCultureCode = portal.DefaultLanguage; } } //now that the culture code is known, look up the correct portal alias for this portalid/culture code var cpa = primaryAliases.GetAliasByPortalIdAndSettings(result.PortalId, result, requestCultureCode, settings); if (cpa != null) { //if an alias was found that matches the request and the culture code, then run with that string rightAlias = cpa.HTTPAlias; //will cause a redirect to the primary portal alias - we know now that there was no custom alias tab //found, so it's just a plain wrong alias ConfigurePortalAliasRedirect(ref result, wrongAlias, rightAlias, true, settings.InternalAliasList, settings); } } } else { //then check to make sure it's the chosen portal alias for this portal //627 : don't do it if we're redirecting to the host portal if (result.RedirectAllowed && result.Reason != RedirectReason.Host_Portal_Used) { string primaryAlias; //checking again in case the rewriting operation changed the values for the valid portal alias bool incorrectAlias = IsPortalAliasIncorrect(context, request, requestUri, result, queryStringCol, settings, parentTraceId, out primaryAlias); if (incorrectAlias) RedirectPortalAlias(primaryAlias, ref result, settings); } } //check to see if we have to avoid the core 302 redirect for the portal alias that is in the /defualt.aspx //for child portals //exception to that is when a custom alias is used but no rewrite has taken place if (result.DoRewrite == false && (result.Action == ActionType.Continue || (result.Action == ActionType.CheckFor301 && result.Reason == RedirectReason.Custom_Tab_Alias))) { string aliasQuerystring; bool isChildAliasRootUrl = CheckForChildPortalRootUrl(requestUri.AbsoluteUri, result, out aliasQuerystring); if (isChildAliasRootUrl) { RewriteAsChildAliasRoot(context, result, aliasQuerystring, settings); } } }
protected string AddPortalAlias(string portalAlias, int portalID) { if (!String.IsNullOrEmpty(portalAlias)) { if (portalAlias.IndexOf("://") != -1) { portalAlias = portalAlias.Remove(0, portalAlias.IndexOf("://") + 3); } var objPortalAliasController = new PortalAliasController(); var objPortalAlias = objPortalAliasController.GetPortalAlias(portalAlias, portalID); if (objPortalAlias == null) { objPortalAlias = new PortalAliasInfo { PortalID = portalID, HTTPAlias = portalAlias }; objPortalAliasController.AddPortalAlias(objPortalAlias); } } return portalAlias; }
private static PortalAliasInfo GetAliasForPortal(string httpAlias, int portalId, ref List<string> messages) { //if no match found, then call database to find (don't rely on cache for this one, because it is an exception event, not an expected event) var pac = new PortalAliasController(); PortalAliasInfo alias = pac.GetPortalAlias(httpAlias, portalId); if (alias == null) { //no match between alias and portal id var aliasArray = TestablePortalAliasController.Instance.GetPortalAliasesByPortalId(portalId).ToList(); if (aliasArray.Count > 0) { alias = aliasArray[0]; //nab the first one here messages.Add("Portal Id " + portalId.ToString() + " does not match http alias " + httpAlias + " - " + alias.HTTPAlias + " was used instead"); } else { messages.Add("Portal Id " + portalId.ToString() + " does not match http alias and no usable alias could be found"); } } return alias; }
private string FriendlyUrlInternal(TabInfo tab, string path, string pageName, string portalAlias, PortalSettings portalSettings) { Guid parentTraceId = Guid.Empty; int portalId = (portalSettings != null) ? portalSettings.PortalId : tab.PortalID; bool cultureSpecificAlias; var localSettings = Settings; //Call GetFriendlyAlias to get the Alias part of the url if (String.IsNullOrEmpty(portalAlias) && portalSettings != null) { portalAlias = portalSettings.PortalAlias.HTTPAlias; } string friendlyPath = GetFriendlyAlias(path, ref portalAlias, portalId, localSettings, portalSettings, out cultureSpecificAlias); if (portalSettings != null) { CheckAndUpdatePortalSettingsForNewAlias(portalSettings, cultureSpecificAlias, portalAlias); } if (tab == null && path == "~/" && String.Compare(pageName, Globals.glbDefaultPage, StringComparison.OrdinalIgnoreCase) == 0) { //this is a request for the site root for he dnn logo skin object (642) //do nothing, the friendly alias is already correct - we don't want to append 'default.aspx' on the end } else { //Get friendly path gets the standard dnn-style friendly path friendlyPath = GetFriendlyQueryString(tab, friendlyPath, pageName, localSettings); if (portalSettings == null) { var pac = new PortalAliasController(); PortalAliasInfo alias = pac.GetPortalAlias(portalAlias, tab.PortalID); portalSettings = new PortalSettings(tab.TabID, alias); } //ImproveFriendlyUrl will attempt to remove tabid/nn and other information from the Url friendlyPath = ImproveFriendlyUrl(tab, friendlyPath, pageName, portalSettings, false, cultureSpecificAlias, localSettings, parentTraceId); } //set it to lower case if so allowed by settings friendlyPath = ForceLowerCaseIfAllowed(tab, friendlyPath, localSettings); return friendlyPath; }
private static void CheckAndUpdatePortalSettingsForNewAlias(PortalSettings portalSettings, bool cultureSpecificAlias, string portalAlias) { if (cultureSpecificAlias && portalAlias != portalSettings.PortalAlias.HTTPAlias) { //was a change in alias, need to update the portalSettings with a new portal alias var pac = new PortalAliasController(); PortalAliasInfo pa = pac.GetPortalAlias(portalAlias, portalSettings.PortalId); if (pa != null) { portalSettings.PortalAlias = pa; } } }
/// <summary> /// Creates a new portal alias /// </summary> /// <param name="PortalId">Id of the portal</param> /// <param name="PortalAlias">Portal Alias to be created</param> /// <history> /// [cnurse] 01/11/2005 created /// </history> public void AddPortalAlias( int PortalId, string PortalAlias ) { PortalAliasController objPortalAliasController = new PortalAliasController(); //Check if the Alias exists PortalAliasInfo objPortalAliasInfo = objPortalAliasController.GetPortalAlias( PortalAlias, PortalId ); //If alias does not exist add new if( objPortalAliasInfo == null ) { objPortalAliasInfo = new PortalAliasInfo(); objPortalAliasInfo.PortalID = PortalId; objPortalAliasInfo.HTTPAlias = PortalAlias; objPortalAliasController.AddPortalAlias( objPortalAliasInfo ); } }
/// ----------------------------------------------------------------------------- /// <summary> /// Creates a new portal alias /// </summary> /// <param name="portalId">Id of the portal</param> /// <param name="portalAlias">Portal Alias to be created</param> /// <remarks> /// </remarks> /// <history> /// [cnurse] 01/11/2005 created /// </history> /// ----------------------------------------------------------------------------- public void AddPortalAlias(int portalId, string portalAlias) { var portalAliasController = new PortalAliasController(); //Check if the Alias exists PortalAliasInfo portalAliasInfo = portalAliasController.GetPortalAlias(portalAlias, portalId); //If alias does not exist add new if (portalAliasInfo == null) { portalAliasInfo = new PortalAliasInfo {PortalID = portalId, HTTPAlias = portalAlias, IsPrimary = true}; TestablePortalAliasController.Instance.AddPortalAlias(portalAliasInfo); } }
/// <summary> /// cmdUpdate_Click runs when the Update button is clicked /// </summary> /// <history> /// [cnurse] 01/17/2005 documented /// </history> protected void cmdUpdate_Click( Object sender, EventArgs e ) { try { string strAlias = txtAlias.Text; if( !String.IsNullOrEmpty(strAlias) ) { if( strAlias.IndexOf( "://" ) != - 1 ) { strAlias = strAlias.Remove( 0, strAlias.IndexOf( "://" ) + 3 ); } if( strAlias.IndexOf( "\\\\" ) != - 1 ) { strAlias = strAlias.Remove( 0, strAlias.IndexOf( "\\\\" ) + 2 ); } PortalAliasController p = new PortalAliasController(); if( ViewState["PortalAliasID"] != null ) { PortalAliasInfo objPortalAliasInfo = new PortalAliasInfo(); objPortalAliasInfo.PortalAliasID = Convert.ToInt32( ViewState["PortalAliasID"] ); objPortalAliasInfo.PortalID = Convert.ToInt32( ViewState["PortalID"] ); objPortalAliasInfo.HTTPAlias = strAlias; try { p.UpdatePortalAliasInfo(objPortalAliasInfo); } catch { UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("DuplicateAlias", this.LocalResourceFile), ModuleMessageType.RedError); return; } } else { PortalAliasInfo objPortalAliasInfo; objPortalAliasInfo = p.GetPortalAlias( strAlias, Convert.ToInt32( ViewState["PortalAliasID"] ) ); if( objPortalAliasInfo == null ) { objPortalAliasInfo = new PortalAliasInfo(); objPortalAliasInfo.PortalID = Convert.ToInt32( ViewState["PortalID"] ); objPortalAliasInfo.HTTPAlias = strAlias; p.AddPortalAlias( objPortalAliasInfo ); } else { UI.Skins.Skin.AddModuleMessage( this, Localization.GetString( "DuplicateAlias", this.LocalResourceFile ), ModuleMessageType.RedError ); return; } } UI.Skins.Skin.AddModuleMessage( this, Localization.GetString( "Success", this.LocalResourceFile ), ModuleMessageType.GreenSuccess ); Response.Redirect( Convert.ToString( ViewState["UrlReferrer"] ), true ); } } catch( Exception exc ) //Module failed to load { Exceptions.ProcessModuleLoadException( this, exc ); } }
/// ----------------------------------------------------------------------------- /// <summary> /// Creates a new portal alias /// </summary> /// <param name="portalId">Id of the portal</param> /// <param name="portalAlias">Portal Alias to be created</param> /// <remarks> /// </remarks> /// <history> /// [cnurse] 01/11/2005 created /// </history> /// ----------------------------------------------------------------------------- public void AddPortalAlias(int portalId, string portalAlias) { PortalAliasController portalAliasController = new PortalAliasController(); //Check if the Alias exists PortalAliasInfo portalAliasInfo = portalAliasController.GetPortalAlias(portalAlias, portalId); //If alias does not exist add new if (portalAliasInfo == null) { portalAliasInfo = new PortalAliasInfo(); portalAliasInfo.PortalID = portalId; portalAliasInfo.HTTPAlias = portalAlias; portalAliasController.AddPortalAlias(portalAliasInfo); } }