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 IHttpHandler GetDnnHttpHandler(RequestContext requestContext, int portal, int tab, string[] passThrough) { PortalController pcontroller = new PortalController(); PortalInfo pinfo = pcontroller.GetPortal(portal); PortalAliasController pacontroller = new PortalAliasController(); PortalAliasCollection pacollection = pacontroller.GetPortalAliasByPortalID(portal); //pacollection. //PortalSettings psettings = new PortalSettings(pinfo); PortalSettings psettings = new PortalSettings(tab, portal); // 64 is the stats tab. TODO: get by page name and not hardcoded id foreach (string key in pacollection.Keys) { psettings.PortalAlias = pacollection[key]; } TabController tcontroller = new TabController(); // psettings.ActiveTab = tcontroller.GetTab(57, 0, true); // 57 is the profile tab. requestContext.HttpContext.Items["PortalSettings"] = psettings; requestContext.HttpContext.Items["UrlRewrite:OriginalUrl"] = requestContext.HttpContext.Request.RawUrl; //UserInfo uinfo = requestContext.HttpContext.User == null ? new UserInfo() : UserController.GetUserByName(psettings.PortalId, requestContext.HttpContext.User.Identity.Name); UserInfo uinfo = requestContext.HttpContext.User == null ? new UserInfo() : UserController.GetCachedUser(psettings.PortalId, requestContext.HttpContext.User.Identity.Name); requestContext.HttpContext.Items["UserInfo"] = uinfo; foreach (string s in passThrough) { requestContext.HttpContext.Items[s] = requestContext.RouteData.Values[s]; } IHttpHandler page = BuildManager.CreateInstanceFromVirtualPath(VirtualPath, typeof(DotNetNuke.Framework.PageBase)) as IHttpHandler; return page; }
public static PortalAliasCollection GetPortalAliasLookup() { PortalAliasCollection objPortalAliasCollection = (PortalAliasCollection)DataCache.GetCache("GetPortalByAlias"); try { if (objPortalAliasCollection == null) { PortalAliasController objPortalAliasController = new PortalAliasController(); objPortalAliasCollection = objPortalAliasController.GetPortalAliases(); DataCache.SetCache("GetPortalByAlias", objPortalAliasCollection); } } catch (Exception exc) { // this is the first data access in Begin_Request and will catch any general connection issues HttpContext objHttpContext = HttpContext.Current; StreamReader objStreamReader; objStreamReader = File.OpenText(objHttpContext.Server.MapPath("~/500.htm")); string strHTML = objStreamReader.ReadToEnd(); objStreamReader.Close(); strHTML = strHTML.Replace("[MESSAGE]", "ERROR: Could not connect to database.<br><br>" + exc.Message); objHttpContext.Response.Write(strHTML); objHttpContext.Response.End(); } return(objPortalAliasCollection); }
protected void CmdSwitchClick(object sender, EventArgs e) { try { if ((!string.IsNullOrEmpty(SitesLst.SelectedValue))) { int selectedPortalID = int.Parse(SitesLst.SelectedValue); var portalAliasCtrl = new PortalAliasController(); ArrayList portalAliases = portalAliasCtrl.GetPortalAliasArrayByPortalID(selectedPortalID); if (((portalAliases != null) && portalAliases.Count > 0 && (portalAliases[0] != null))) { Response.Redirect(Globals.AddHTTP(((PortalAliasInfo) portalAliases[0]).HTTPAlias)); } } } catch(ThreadAbortException) { //Do nothing we are not logging ThreadAbortxceptions caused by redirects } catch (Exception ex) { Exceptions.LogException(ex); } }
private void BindData() { ArrayList arr; PortalAliasController p = new PortalAliasController(); arr = p.GetPortalAliasArrayByPortalID( intPortalID ); dgPortalAlias.DataSource = arr; dgPortalAlias.DataBind(); }
public static PortalAliasCollection GetPortalAliasLookup() { var portalAliasCollection = new PortalAliasCollection(); var aliasController = new PortalAliasController(); foreach (var kvp in aliasController.GetPortalAliasesInternal()) { portalAliasCollection.Add(kvp.Key, kvp.Value); } return(portalAliasCollection); }
/// <inheritdoc/> string IPortalAliasService.GetPortalAliasByPortal(int portalId, string portalAlias) { string retValue = string.Empty; bool foundAlias = false; var portalAliasInfo = this.ThisAsInterface.GetPortalAlias(portalAlias, portalId); if (portalAliasInfo != null) { retValue = portalAliasInfo.HttpAlias; foundAlias = true; } if (!foundAlias) { // searching from longest to shortest alias ensures that the most specific portal is matched first // In some cases this method has been called with "portalaliases" that were not exactly the real portal alias // the startswith behaviour is preserved here to support those non-specific uses var controller = new PortalAliasController(); var portalAliases = controller.GetPortalAliasesInternal(); var portalAliasCollection = portalAliases.OrderByDescending(k => k.Key.Length); foreach (var currentAlias in portalAliasCollection) { // check if the alias key starts with the portal alias value passed in - we use // StartsWith because child portals are redirected to the parent portal domain name // eg. child = 'www.domain.com/child' and parent is 'www.domain.com' // this allows the parent domain name to resolve to the child alias ( the tabid still identifies the child portalid ) IPortalAliasInfo currentAliasInfo = currentAlias.Value; string httpAlias = currentAliasInfo.HttpAlias.ToLowerInvariant(); if (httpAlias.StartsWith(portalAlias.ToLowerInvariant()) && currentAliasInfo.PortalId == portalId) { retValue = currentAliasInfo.HttpAlias; break; } httpAlias = httpAlias.StartsWith("www.") ? httpAlias.Replace("www.", string.Empty) : string.Concat("www.", httpAlias); if (httpAlias.StartsWith(portalAlias.ToLowerInvariant()) && currentAliasInfo.PortalId == portalId) { retValue = currentAliasInfo.HttpAlias; break; } } } return(retValue); }
/// <summary> /// Gets the data to send to the Glimpse client. /// </summary> /// <param name="context">The context.</param> /// <returns>Data to send the the Glimpse client.</returns> public object GetData(HttpContextBase context) { try { // get variables we'll need to output var portalSettings = PortalSettings.Current; var tabCreatedByUser = UserController.GetUserById(-1, portalSettings.ActiveTab.CreatedByUserID); var tabModifiedByUser = UserController.GetUserById(-1, portalSettings.ActiveTab.LastModifiedByUserID); var portalAliases = new PortalAliasController().GetPortalAliasArrayByPortalID(portalSettings.PortalId) .Cast<PortalAliasInfo>() .Select(p => p.HTTPAlias); var contextItems = new List<object[]> { new object[] { "Key", "Value" } }; foreach (var itemKey in context.Items.Keys) contextItems.Add(new object[] { itemKey.ToString(), context.Items[itemKey].ToString() }); // add to data to send var data = new List<object[]> { new object[] { "Property", "Value" } }; data.Add(new object[] { "PortalID", portalSettings.PortalId }); data.Add(new object[] { "Portal Name", portalSettings.PortalName }); data.Add(new object[] { "Portal Aliases", portalAliases.ToArray() }); data.Add(new object[] { "Portal SSL Enabled", portalSettings.SSLEnabled }); data.Add(new object[] { "Portal SSL Enforced", portalSettings.SSLEnforced }); data.Add(new object[] { "User ID", portalSettings.UserId }); data.Add(new object[] { "User Name", portalSettings.UserInfo.Username }); data.Add(new object[] { "User Roles", portalSettings.UserInfo.Roles }); data.Add(new object[] { "Tab ID", portalSettings.ActiveTab.TabID }); data.Add(new object[] { "Tab Name", portalSettings.ActiveTab.TabName }); data.Add(new object[] { "Tab Title", portalSettings.ActiveTab.Title }); data.Add(new object[] { "Tab Path", portalSettings.ActiveTab.TabPath }); data.Add(new object[] { "Tab SSL Enabled", portalSettings.ActiveTab.IsSecure }); data.Add(new object[] { "Tab Created By", (tabCreatedByUser == null) ? null : tabCreatedByUser.Username }); data.Add(new object[] { "Tab Created Date", portalSettings.ActiveTab.CreatedOnDate }); data.Add(new object[] { "Tab Modified By", (tabModifiedByUser == null) ? null : tabModifiedByUser.Username }); data.Add(new object[] { "Tab Modified Date", portalSettings.ActiveTab.LastModifiedOnDate }); data.Add(new object[] { "Tab Skin Path", portalSettings.ActiveTab.SkinPath }); data.Add(new object[] { "Tab Skin Source", portalSettings.ActiveTab.SkinSrc }); data.Add(new object[] { "Context Items", contextItems }); return data; } catch (Exception ex) { DotNetNuke.Services.Exceptions.Exceptions.LogException(ex); return null; } }
private void Page_Load(object sender, System.EventArgs e) { RotatorSettings rotatorSettings = new RotatorSettings(); rotatorSettings.Hosts = new System.Collections.Generic.List<System.Web.UI.WebControls.ListItem>(); PortalAliasController paCtrl = new PortalAliasController(); foreach (DictionaryEntry de in paCtrl.GetPortalAliases()) { PortalAliasInfo paInfo = (PortalAliasInfo)de.Value; rotatorSettings.Hosts.Add(new ListItem(paInfo.HTTPAlias, paInfo.HTTPAlias)); } Control ctrlAct = LoadControl(TemplateSourceDirectory.TrimEnd('/') + "/RegCore/QuickStatusAndLink.ascx"); (ctrlAct as IRegCoreComponent).InitRegCore(IsAdmin, RotatorSettings.RegCoreServer, RotatorSettings.ProductName, RotatorSettings.ProductCode, RotatorSettings.ProductKey, RotatorSettings.Version, TemplateSourceDirectory.TrimEnd('/') + "/RegCore/", typeof(DynamicRotatorController)); this.pnlAdmin.Controls.Add(ctrlAct); if (!rotatorSettings.IsActivated() || rotatorSettings.IsTrialExpired()) { DynamicRotator.Visible = false; } }
/// <summary> /// BindData fetches the data from the database and updates the controls /// </summary> /// <history> /// [cnurse] 01/17/2005 documented /// </history> private void BindData() { if( Request.QueryString["paid"] != null ) { PortalAliasInfo objPortalAliasInfo; int intPortalAliasID = Convert.ToInt32( Request.QueryString["paid"] ); PortalAliasController p = new PortalAliasController(); objPortalAliasInfo = p.GetPortalAliasByPortalAliasID( intPortalAliasID ); ViewState.Add( "PortalAliasID", intPortalAliasID ); ViewState.Add( "PortalID", objPortalAliasInfo.PortalID ); if( ! UserInfo.IsSuperUser ) { if( objPortalAliasInfo.PortalID != PortalSettings.PortalId ) { UI.Skins.Skin.AddModuleMessage( this, "You do not have access to view this Portal Alias.", ModuleMessageType.RedError ); return; } } txtAlias.Text = objPortalAliasInfo.HTTPAlias; SetDeleteVisibility( objPortalAliasInfo.PortalID ); } else if( Request.QueryString["pid"] != "" ) { if( UserInfo.IsSuperUser ) { ViewState.Add( "PortalID", Convert.ToInt32( Request.QueryString["pid"] ) ); } SetDeleteVisibility( Convert.ToInt32( Request.QueryString["pid"] ) ); } else { ViewState.Add( "PortalID", PortalSettings.PortalId ); SetDeleteVisibility( PortalSettings.PortalId ); } }
/// ----------------------------------------------------------------------------- /// <summary> /// FormatExpiryDate formats the format name as an a tag /// </summary> /// <remarks> /// </remarks> /// <history> /// [cnurse] 9/28/2004 Updated to reflect design changes for Help, 508 support /// and localisation /// </history> /// ----------------------------------------------------------------------------- public string FormatPortalAliases(int portalID) { var str = new StringBuilder(); try { var objPortalAliasController = new PortalAliasController(); var arr = objPortalAliasController.GetPortalAliasArrayByPortalID(portalID); PortalAliasInfo objPortalAliasInfo; int i; for (i = 0; i <= arr.Count - 1; i++) { objPortalAliasInfo = (PortalAliasInfo) arr[i]; var httpAlias = Globals.AddHTTP(objPortalAliasInfo.HTTPAlias); var originalUrl = HttpContext.Current.Items["UrlRewrite:OriginalUrl"].ToString().ToLowerInvariant(); httpAlias = Globals.AddPort(httpAlias, originalUrl); str.Append("<a href=\"" + httpAlias + "\">" + objPortalAliasInfo.HTTPAlias + "</a>" + "<BR>"); } } catch (Exception exc) //Module failed to load { Exceptions.ProcessModuleLoadException(this, exc); } return str.ToString(); }
/// ----------------------------------------------------------------------------- /// <summary> /// DeleteAlias runs when a delete button is clicked /// </summary> /// <remarks> /// </remarks> /// <history> /// [cnurse] 12/12/2008 Created /// </history> /// ----------------------------------------------------------------------------- private void DeleteAlias(object source, DataGridCommandEventArgs e) { var controller = new PortalAliasController(); //Get the index of the row to delete int index = e.Item.ItemIndex; //Remove the alias from the aliases collection var portalAlias = (PortalAliasInfo) Aliases[index]; controller.DeletePortalAlias(portalAlias.PortalAliasID); //Rebind the collection _Aliases = null; BindAliases(); }
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 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); } } }
public static PortalAliasCollection GetPortalAliasLookup() { var portalAliasCollection = new PortalAliasCollection(); var aliasController = new PortalAliasController(); foreach (var kvp in aliasController.GetPortalAliasesInternal()) { portalAliasCollection.Add(kvp.Key, kvp.Value); } return portalAliasCollection; }
protected void OnPortalAliasesChanged(object sender, EventArgs e) { var aliases = new PortalAliasController().GetPortalAliasArrayByPortalID(_portalId); BindDefaultAlias(aliases); }
private void BindAliases(PortalInfo portal) { var portalSettings = new PortalSettings(portal); var portalAliasController = new PortalAliasController(); var aliases = portalAliasController.GetPortalAliasArrayByPortalID(portal.PortalID); var portalAliasMapping = portalSettings.PortalAliasMappingMode.ToString().ToUpper(); if (String.IsNullOrEmpty(portalAliasMapping)) { portalAliasMapping = "CANONICALURL"; } portalAliasModeButtonList.Select(portalAliasMapping, false); if (portalAliasMapping.ToUpperInvariant() == "NONE") { defaultAliasRow.Visible = false; } else { defaultAliasRow.Visible = true; defaultAliasDropDown.DataSource = aliases; defaultAliasDropDown.DataBind(); var defaultAlias = PortalController.GetPortalSetting("DefaultPortalAlias", portal.PortalID, ""); if (defaultAliasDropDown.Items.FindByValue(defaultAlias) != null) { defaultAliasDropDown.Items.FindByValue(defaultAlias).Selected = true; } } //Auto Add Portal Alias if (new PortalController().GetPortals().Count > 1) { chkAutoAddPortalAlias.Enabled = false; chkAutoAddPortalAlias.Checked = false; } else { chkAutoAddPortalAlias.Checked = HostController.Instance.GetBoolean("AutoAddPortalAlias"); } }
private IPortalAliasInfo GetPortalAliasInternal(string httpAlias) { string strPortalAlias; // try the specified alias first IPortalAliasInfo portalAlias = this.GetPortalAliasLookupInternal(httpAlias.ToLowerInvariant()); // domain.com and www.domain.com should be synonymous if (portalAlias == null) { if (httpAlias.StartsWith("www.", StringComparison.InvariantCultureIgnoreCase)) { // try alias without the "www." prefix strPortalAlias = httpAlias.Replace("www.", string.Empty); } else // try the alias with the "www." prefix { strPortalAlias = string.Concat("www.", httpAlias); } // perform the lookup portalAlias = this.GetPortalAliasLookupInternal(strPortalAlias.ToLowerInvariant()); } // allow domain wildcards if (portalAlias == null) { // remove the domain prefix ( ie. anything.domain.com = domain.com ) if (httpAlias.IndexOf(".", StringComparison.Ordinal) != -1) { strPortalAlias = httpAlias.Substring(httpAlias.IndexOf(".", StringComparison.Ordinal) + 1); } else // be sure we have a clean string (without leftovers from preceding 'if' block) { strPortalAlias = httpAlias; } // try an explicit lookup using the wildcard entry ( ie. *.domain.com ) portalAlias = this.GetPortalAliasLookupInternal("*." + strPortalAlias.ToLowerInvariant()) ?? this.GetPortalAliasLookupInternal(strPortalAlias.ToLowerInvariant()); if (portalAlias == null) { // try a lookup using "www." + raw domain portalAlias = this.GetPortalAliasLookupInternal("www." + strPortalAlias.ToLowerInvariant()); } } if (portalAlias == null) { // check if this is a fresh install ( no alias values in collection ) var controller = new PortalAliasController(); var portalAliases = controller.GetPortalAliasesInternal(); if (portalAliases.Keys.Count == 0 || (portalAliases.Count == 1 && portalAliases.ContainsKey("_default"))) { // relate the PortalAlias to the default portal on a fresh database installation DataProvider.Instance().UpdatePortalAlias(httpAlias.ToLowerInvariant().Trim('/'), UserController.Instance.GetCurrentUserInfo().UserID); EventLogController.Instance.AddLog( "PortalAlias", httpAlias, PortalController.Instance.GetCurrentSettings(), UserController.Instance.GetCurrentUserInfo().UserID, EventLogController.EventLogType.PORTALALIAS_UPDATED); // clear the cachekey "GetPortalByAlias" otherwise portalalias "_default" stays in cache after first install DataCache.RemoveCache("GetPortalByAlias"); // try again portalAlias = this.GetPortalAliasLookupInternal(httpAlias.ToLowerInvariant()); } } return(portalAlias); }
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 void BindMarketing(PortalInfo portal) { //Load DocTypes var searchEngines = new Dictionary<string, string> { { "Google", "http://www.google.com/addurl?q=" + Globals.HTTPPOSTEncode(Globals.AddHTTP(Globals.GetDomainName(Request))) }, { "Yahoo", "http://siteexplorer.search.yahoo.com/submit" }, { "Microsoft", "http://search.msn.com.sg/docs/submit.aspx" } }; cboSearchEngine.DataSource = searchEngines; cboSearchEngine.DataBind(); var portalAliasController = new PortalAliasController(); var aliases = portalAliasController.GetPortalAliasArrayByPortalID(portal.PortalID); if (PortalController.IsChildPortal(portal, Globals.GetAbsoluteServerPath(Request))) { txtSiteMap.Text = Globals.AddHTTP(Globals.GetDomainName(Request)) + @"/SiteMap.aspx?portalid=" + portal.PortalID; } else { if (aliases.Count > 0) { //Get the first Alias var objPortalAliasInfo = (PortalAliasInfo)aliases[0]; txtSiteMap.Text = Globals.AddHTTP(objPortalAliasInfo.HTTPAlias) + @"/SiteMap.aspx"; } else { txtSiteMap.Text = Globals.AddHTTP(Globals.GetDomainName(Request)) + @"/SiteMap.aspx"; } } optBanners.SelectedIndex = portal.BannerAdvertising; if (UserInfo.IsSuperUser) { lblBanners.Visible = false; } else { optBanners.Enabled = portal.BannerAdvertising != 2; lblBanners.Visible = portal.BannerAdvertising == 2; } }
private void BindAliases(PortalInfo portal) { var portalSettings = new PortalSettings(portal); var portalAliasController = new PortalAliasController(); var aliases = portalAliasController.GetPortalAliasArrayByPortalID(portal.PortalID); var portalAliasMapping = portalSettings.PortalAliasMappingMode.ToString().ToUpper(); if (String.IsNullOrEmpty(portalAliasMapping)) { portalAliasMapping = "CANONICALURL"; } portalAliasModeButtonList.Select(portalAliasMapping, false); BindDefaultAlias(aliases); //Auto Add Portal Alias if (new PortalController().GetPortals().Count > 1) { chkAutoAddPortalAlias.Enabled = false; chkAutoAddPortalAlias.Checked = false; } else { chkAutoAddPortalAlias.Checked = HostController.Instance.GetBoolean("AutoAddPortalAlias"); } }
private bool IsChildPortal(PortalSettings ps, HttpContext context) { var isChild = false; var aliasController = new PortalAliasController(); var arr = aliasController.GetPortalAliasArrayByPortalID(ps.PortalId); var serverPath = Globals.GetAbsoluteServerPath(context.Request); if (arr.Count > 0) { var portalAlias = (PortalAliasInfo)arr[0]; var portalName = Globals.GetPortalDomainName(ps.PortalAlias.HTTPAlias, Request, true); if (portalAlias.HTTPAlias.IndexOf("/") > -1) { portalName = PortalController.GetPortalFolder(portalAlias.HTTPAlias); } if (!string.IsNullOrEmpty(portalName) && Directory.Exists(serverPath + portalName)) { isChild = true; } } return isChild; }
protected string GetFormattedLink(object dataItem) { var returnValue = new StringBuilder(); if ((dataItem is TabInfo)) { var tab = (TabInfo) dataItem; if ((tab != null)) { int index = 0; TabCtrl.PopulateBreadCrumbs(ref tab); foreach (TabInfo t in tab.BreadCrumbs) { if ((index > 0)) { returnValue.Append(" > "); } if ((tab.BreadCrumbs.Count - 1 == index)) { string url; var objPortalAliasController = new PortalAliasController(); ArrayList arr = objPortalAliasController.GetPortalAliasArrayByPortalID(t.PortalID); var objPortalAliasInfo = (PortalAliasInfo) arr[0]; url = Globals.AddHTTP(objPortalAliasInfo.HTTPAlias) + "/Default.aspx?tabId=" + t.TabID; returnValue.AppendFormat("<a href=\"{0}\">{1}</a>", url, t.LocalizedTabName); } else { returnValue.AppendFormat("{0}", t.LocalizedTabName); } index = index + 1; } } } return returnValue.ToString(); }
/// <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> /// Returns a list of tab and redirects from the database, for the specified portal /// Assumes that the dictionary should have any existing items replaced if the portalid is specified /// and the portal tabs already exist in the dictionary. /// </summary> /// <param name="existingTabs"></param> /// <param name="portalId"></param> /// <param name="settings"></param> /// <param name="customAliasTabs"></param> /// <remarks> /// Each dictionary entry in the return value is a complex data type of another dictionary that is indexed by the url culture. If there is /// only one culture for the Url, it will be that culture. /// </remarks> /// <returns></returns> private static SharedDictionary<int, SharedDictionary<string, string>> BuildUrlDictionary(SharedDictionary<int, SharedDictionary<string, string>> existingTabs, int portalId, FriendlyUrlSettings settings, ref SharedDictionary<string, string> customAliasTabs) { //fetch tabs with redirects var tabs = FriendlyUrlController.GetTabs(portalId, false, null, settings); if (existingTabs == null) { existingTabs = new SharedDictionary<int, SharedDictionary<string, string>>(); } if (customAliasTabs == null) { customAliasTabs = new SharedDictionary<string, string>(); } //go through each tab in the found list foreach (TabInfo tab in tabs.Values) { //check the custom alias tabs collection and add to the dictionary where necessary foreach (var customAlias in tab.CustomAliases) { string key = tab.TabID.ToString() + ":" + customAlias.Key; using (customAliasTabs.GetWriteLock()) //obtain write lock on custom alias Tabs { if (customAliasTabs.ContainsKey(key) == false) { customAliasTabs.Add(key, customAlias.Value); } } } foreach (TabUrlInfo redirect in tab.TabUrls) { if (redirect.HttpStatus == "200") { string url = redirect.Url; //770 : add in custom alias into the tab path for the custom Urls if (redirect.PortalAliasUsage != PortalAliasUsageType.Default && redirect.PortalAliasId > 0) { //there is a custom http alias specified for this portal alias var pac = new PortalAliasController(); PortalAliasInfo alias = pac.GetPortalAliasByPortalAliasID(redirect.PortalAliasId); if (alias != null) { string customHttpAlias = alias.HTTPAlias; url = customHttpAlias + "::" + url; } } string cultureKey = redirect.CultureCode.ToLower(); int tabid = tab.TabID; using (existingTabs.GetWriteLock()) { if (existingTabs.ContainsKey(tabid) == false) { var entry = new SharedDictionary<string, string>(); using (entry.GetWriteLock()) { entry.Add(cultureKey, url); } //871 : use lower case culture code as key existingTabs.Add(tab.TabID, entry); } else { SharedDictionary<string, string> entry = existingTabs[tabid]; //replace tab if existing but was retreieved from tabs call if (tab.PortalID == portalId || portalId == -1) { using (entry.GetWriteLock()) { if (entry.ContainsKey(cultureKey) == false) { //add the culture and set in parent dictionary //871 : use lower case culture code as key entry.Add(cultureKey, url); existingTabs[tabid] = entry; } } } } } } } } return existingTabs; }
public static string DeletePortal( PortalInfo portal, string serverPath ) { string strPortalName = null; string strMessage = string.Empty; // check if this is the last portal int portalCount = DataProvider.Instance().GetPortalCount(); if( portalCount > 1 ) { if( portal != null ) { // delete custom resource files Globals.DeleteFilesRecursive( serverPath, ".Portal-" + portal.PortalID.ToString() + ".resx" ); //If child portal delete child folder PortalAliasController objPortalAliasController = new PortalAliasController(); ArrayList arr = objPortalAliasController.GetPortalAliasArrayByPortalID( portal.PortalID ); PortalAliasInfo objPortalAliasInfo = (PortalAliasInfo)( arr[0] ); strPortalName = Globals.GetPortalDomainName( objPortalAliasInfo.HTTPAlias, null, true ); if( Convert.ToBoolean( ( objPortalAliasInfo.HTTPAlias.IndexOf( "/", 0 ) + 1 ) ) ) { strPortalName = objPortalAliasInfo.HTTPAlias.Substring( ( objPortalAliasInfo.HTTPAlias.LastIndexOf( "/" ) + 1 ) ); } if( strPortalName != "" && Directory.Exists( serverPath + strPortalName ) ) { Globals.DeleteFolderRecursive( serverPath + strPortalName ); } // delete upload directory Globals.DeleteFolderRecursive( serverPath + "Portals\\" + portal.PortalID.ToString() ); string HomeDirectory = portal.HomeDirectoryMapPath; if( Directory.Exists( HomeDirectory ) ) { Globals.DeleteFolderRecursive( HomeDirectory ); } // remove database references PortalController objPortalController = new PortalController(); objPortalController.DeletePortalInfo( portal.PortalID ); } } else { strMessage = Localization.GetString( "LastPortal" ); } return strMessage; }
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); } } }
public static string GetPortalByID(int portalId, string portalAlias) { return(PortalAliasController.GetPortalAliasByPortal(portalId, portalAlias)); }
private static void AddCustomRedirectsToDictionary(SharedDictionary<string, string> tabIndex, Dictionary<string, DupKeyCheck> dupCheck, string httpAlias, TabInfo tab, FriendlyUrlSettings settings, FriendlyUrlOptions options, ref string rewritePath, out int tabPathDepth, ref List<string> customHttpAliasesUsed, bool isDeleted, Guid parentTraceId) { tabPathDepth = 1; var duplicateHandlingPreference = UrlEnums.TabKeyPreference.TabRedirected; bool checkForDupUrls = settings.CheckForDuplicateUrls; //697 : custom url rewrites with large number of path depths fail because of incorrect path depth calculation int maxTabPathDepth = 1; string newRewritePath = rewritePath; string aliasCulture = null; //get the culture for this alias var primaryAliases = TestablePortalAliasController.Instance.GetPortalAliasesByPortalId(tab.PortalID).ToList(); if (primaryAliases.Count > 0) { aliasCulture = primaryAliases.GetCultureByPortalIdAndAlias(tab.PortalID, httpAlias); } foreach (var redirect in tab.TabUrls) { //allow for additional qs parameters if (!String.IsNullOrEmpty(redirect.QueryString)) { rewritePath += (redirect.QueryString.StartsWith("&")) ? redirect.QueryString : "&" + redirect.QueryString; } string redirectTabPath = redirect.Url; string redirectedRewritePath = rewritePath; //770 : allow for custom portal aliases string redirectAlias = httpAlias; if (redirect.PortalAliasId > 0) { //has a custom portal alias var pac = new PortalAliasController(); PortalAliasInfo customAlias = pac.GetPortalAliasByPortalAliasID(redirect.PortalAliasId); if (customAlias != null) { //this will be used to add the Url to the dictionary redirectAlias = customAlias.HTTPAlias; //add to the list of custom aliases used by the portal if (customHttpAliasesUsed == null) { customHttpAliasesUsed = new List<string>(); } if (!customHttpAliasesUsed.Contains(redirectAlias)) { customHttpAliasesUsed.Add(redirectAlias); } } } //set the redirect status using the httpStatus switch (redirect.HttpStatus) { case "301": redirectedRewritePath = RedirectTokens.AddRedirectReasonToRewritePath(rewritePath, ActionType.Redirect301, RedirectReason.Custom_Redirect); break; case "302": redirectedRewritePath = RedirectTokens.AddRedirectReasonToRewritePath(rewritePath, ActionType.Redirect302, RedirectReason.Custom_Redirect); break; case "404": redirectedRewritePath = RedirectTokens.AddRedirectReasonToRewritePath(rewritePath, ActionType.Output404, RedirectReason.Custom_Redirect); break; case "200": //when there is a 200, then replace the 'standard' path newRewritePath = RedirectTokens.AddRedirectReasonToRewritePath(newRewritePath, ActionType.CheckFor301, RedirectReason.Custom_Redirect); //672 : replacement urls have preference over all redirects, deleted tabs and standard urls duplicateHandlingPreference = UrlEnums.TabKeyPreference.TabOK; break; } //check the culture of the redirect to see if it either doesn't match the alias or needs to specify //the language when requested if (redirect.CultureCode != null) { if (redirect.CultureCode != "" && redirect.CultureCode != "Default") { //806 : specify duplicates where the alias culture doesn't match the redirect culture //so that redirect to the best match between alias culture and redirect culture //compare the supplied alias culture with the redirect culture //856 : if alias culture == "" and a custom 301 redirect then redirects are forced if (!string.IsNullOrEmpty(aliasCulture) && aliasCulture != redirect.CultureCode) { //the culture code and the specific culture alias don't match //set 301 check status and set to delete if a duplicate is found redirectedRewritePath = RedirectTokens.AddRedirectReasonToRewritePath( redirectedRewritePath, ActionType.CheckFor301, RedirectReason.Custom_Redirect); newRewritePath = RedirectTokens.AddRedirectReasonToRewritePath(newRewritePath, ActionType.CheckFor301, RedirectReason.Custom_Redirect); duplicateHandlingPreference = UrlEnums.TabKeyPreference.TabRedirected; } //add on the culture code for the redirect, so that the rewrite silently sets the culture for the page RewriteController.AddLanguageCodeToRewritePath(ref redirectedRewritePath, redirect.CultureCode); } } //now add the custom redirect to the tab dictionary if (String.Compare(httpAlias, redirectAlias, StringComparison.OrdinalIgnoreCase) == 0) { AddToTabDict(tabIndex, dupCheck, httpAlias, redirectTabPath, redirectedRewritePath, tab.TabID, duplicateHandlingPreference, ref tabPathDepth, checkForDupUrls, isDeleted); } else { //770 : there is a specific alias for this tab //if not a redirect already, make it a redirect for the wrong (original) rewrite path string wrongAliasRedirectedRewritePath = RedirectTokens.AddRedirectReasonToRewritePath(redirectedRewritePath, ActionType.Redirect301, RedirectReason.Custom_Tab_Alias); //add in the entry with the specific redirectAlias if (redirectTabPath == "") { //when adding a blank custom Url, also add in a standard tab path url, because any url that also includes querystring data will use the standard tab path string tabPath = GetTabPath(tab, options, parentTraceId); string stdDictRewritePath = RedirectTokens.AddRedirectReasonToRewritePath(rewritePath, ActionType.CheckFor301, RedirectReason.Custom_Tab_Alias); AddToTabDict(tabIndex, dupCheck, redirectAlias, tabPath, stdDictRewritePath, tab.TabID, UrlEnums.TabKeyPreference.TabOK, ref tabPathDepth, checkForDupUrls, isDeleted); //then add in the portal alias with no tabpath (ie like a site root url) AddToTabDict(tabIndex, dupCheck, redirectAlias, redirectTabPath, redirectedRewritePath, tab.TabID, duplicateHandlingPreference, ref tabPathDepth, checkForDupUrls, isDeleted); //838 : disabled tabs with custom aliases - still load the settings page without redirect //disabled / not active by date / external url pages cannot navigate to settings page if (tab.DisableLink || !string.IsNullOrEmpty(tab.Url) || (tab.EndDate < DateTime.Now && tab.EndDate > DateTime.MinValue) || (tab.StartDate > DateTime.Now && tab.StartDate > DateTime.MinValue)) { string settingsUrl = tabPath + "/ctl/Tab"; string settingsRewritePath = CreateRewritePath(tab.TabID, redirect.CultureCode, "ctl=Tab"); //no redirect on the ctl/Tab url //add in the ctl/tab Url for the custom alias, with no redirect so that the page settings can be loaded AddToTabDict(tabIndex, dupCheck, redirectAlias, settingsUrl, settingsRewritePath, tab.TabID, UrlEnums.TabKeyPreference.TabRedirected, ref tabPathDepth, settings.CheckForDuplicateUrls, isDeleted); } } else { //add in custom entry with different alias AddToTabDict(tabIndex, dupCheck, redirectAlias, redirectTabPath, redirectedRewritePath, tab.TabID, duplicateHandlingPreference, ref tabPathDepth, checkForDupUrls, isDeleted); //add in the entry with the original alias, plus an instruction to redirect if it's used AddToTabDict(tabIndex, dupCheck, httpAlias, redirectTabPath, wrongAliasRedirectedRewritePath, tab.TabID, duplicateHandlingPreference, ref tabPathDepth, checkForDupUrls, isDeleted); } } if (tabPathDepth > maxTabPathDepth) { maxTabPathDepth = tabPathDepth; } } //return the highest tabpath depth found tabPathDepth = maxTabPathDepth; //return any changes to the rewritePath rewritePath = newRewritePath; }
public static string GetPortalByTab(int tabID, string portalAlias) { return(PortalAliasController.GetPortalAliasByTab(tabID, portalAlias)); }
protected void SaveAlias(object source, CommandEventArgs e) { var controller = new PortalAliasController(); bool isChild = false; string childPath = string.Empty; string message = string.Empty; //Get the index of the row to save int index = dgPortalAlias.EditItemIndex; var portalAlias = (PortalAliasInfo) Aliases[index]; var ctlAlias = (TextBox) dgPortalAlias.Items[index].Cells[1].FindControl("txtHTTPAlias"); var chkChild = (CheckBox) dgPortalAlias.Items[index].Cells[2].FindControl("chkChild"); string strAlias = ctlAlias.Text.Trim(); if (string.IsNullOrEmpty(strAlias)) { message = Localization.GetString("InvalidAlias", LocalResourceFile); } else { if (strAlias.IndexOf("://") != -1) { strAlias = strAlias.Remove(0, strAlias.IndexOf("://") + 3); } if (strAlias.IndexOf("\\\\") != -1) { strAlias = strAlias.Remove(0, strAlias.IndexOf("\\\\") + 2); } isChild = (chkChild != null && chkChild.Checked); //Validate Alias if (!PortalAliasController.ValidateAlias(strAlias, false)) { message = Localization.GetString("InvalidAlias", LocalResourceFile); } //Validate Child Folder Name if (isChild) { childPath = strAlias.Substring(strAlias.LastIndexOf("/") + 1); if (!PortalAliasController.ValidateAlias(childPath, true)) { message = Localization.GetString("InvalidAlias", LocalResourceFile); } } } if (string.IsNullOrEmpty(message) && isChild) { //Attempt to create child folder string childPhysicalPath = Server.MapPath(childPath); if (Directory.Exists(childPhysicalPath)) { message = Localization.GetString("ChildExists", LocalResourceFile); } else { message = PortalController.CreateChildPortalFolder(childPhysicalPath); } } if (string.IsNullOrEmpty(message)) { portalAlias.HTTPAlias = strAlias; if (AddMode) { controller.AddPortalAlias(portalAlias); } else { controller.UpdatePortalAliasInfo(portalAlias); } //Reset Edit Index lblError.Visible = false; dgPortalAlias.EditItemIndex = -1; _Aliases = null; } else { lblError.Text = message; lblError.Visible = true; } BindAliases(); }
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; } } }
BlogInfo[] IMetaWeblog.GetUsersBlogs(string key, string username, string password) { LocatePortal(Context.Request); DotNetNuke.Entities.Users.UserInfo ui = Authenticate(username, password); if (ui.UserID > 0) { //todo: configure blog info for users var infoList = new List<BlogInfo>(); var bi = new BlogInfo {blogid = "0"}; var pac = new PortalAliasController(); foreach (PortalAliasInfo api in pac.GetPortalAliasArrayByPortalID(PortalId)) { bi.url = "http://" + api.HTTPAlias; break; } bi.blogName = ui.Username; infoList.Add(bi); return infoList.ToArray(); } throw new XmlRpcFaultException(0, Localization.GetString("FailedAuthentication.Text", LocalResourceFile)); }
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; }
/// <summary> /// FormatExpiryDate formats the format name as an <a> tag /// </summary> /// <history> /// [cnurse] 9/28/2004 Updated to reflect design changes for Help, 508 support /// and localisation /// </history> public string FormatPortalAliases( int PortalID ) { StringBuilder str = new StringBuilder(); try { PortalAliasController objPortalAliasController = new PortalAliasController(); ArrayList arr = objPortalAliasController.GetPortalAliasArrayByPortalID( PortalID ); for( int i = 0; i < arr.Count; i++ ) { PortalAliasInfo objPortalAliasInfo = (PortalAliasInfo)arr[i]; str.Append( "<a href=\"" + Globals.AddHTTP( objPortalAliasInfo.HTTPAlias ) + "\">" + objPortalAliasInfo.HTTPAlias + "</a>" + "<BR>" ); } } catch( Exception exc ) //Module failed to load { Exceptions.ProcessModuleLoadException( this, exc ); } return str.ToString(); }
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; }