protected void Page_Load(object sender, EventArgs e) { siteId = QueryHelper.GetInteger("siteid", 0); si = SiteInfoProvider.GetSiteInfo(siteId); int domainAliasId = QueryHelper.GetInteger("domainaliasid", 0); if (!RequestHelper.IsPostBack()) { // Display error from previous save if occurred string runError = QueryHelper.GetString("runerror", String.Empty); string[] collisionSite = runError.Split(';'); if ((collisionSite.Length == 2) && (si != null)) { lblError.Text = String.Format(GetString("SiteDomain.RunError"), HTMLHelper.HTMLEncode(collisionSite[0]), HTMLHelper.HTMLEncode(collisionSite[1]), HTMLHelper.HTMLEncode(si.DisplayName)); lblError.Visible = true; } } InitializeComponents(); if (QueryHelper.GetString("saved", String.Empty) != String.Empty) { lblInfo.Text = GetString("General.ChangesSaved"); lblInfo.Visible = true; } alias = SiteDomainAliasInfoProvider.GetSiteDomainAliasInfo(domainAliasId); if (!RequestHelper.IsPostBack()) { LoadData(); } string currentAlias; // Update breadcrumb label if (alias != null) { currentAlias = alias.SiteDomainAliasName; } else { // New domain alias currentAlias = GetString("SiteDomain.NewAlias"); } // initializes page title control string[,] breadcrumbs = new string[2, 3]; breadcrumbs[0, 0] = GetString("SiteDomain.ItemListLink"); breadcrumbs[0, 1] = ResolveUrl("~/CMSSiteManager/Sites/Site_Edit_DomainAliases.aspx?siteid=" + siteId); breadcrumbs[0, 2] = ""; breadcrumbs[1, 0] = currentAlias; breadcrumbs[1, 1] = ""; breadcrumbs[1, 2] = ""; this.CurrentMaster.Title.Breadcrumbs = breadcrumbs; this.CurrentMaster.Title.HelpTopicName = "edit_and_new_alias"; }
/// <summary> /// Deletes site domain alias. Called when the "Delete alias" button is pressed. /// Expects the CreateSiteDomainAlias method to be run first. /// </summary> private bool DeleteSiteDomainAlias() { // Get the site domain alias SiteDomainAliasInfo deleteAlias = SiteDomainAliasInfoProvider.GetSiteDomainAliasInfo("127.0.0.1", CMSContext.CurrentSiteID); // Delete the site domain alias SiteDomainAliasInfoProvider.DeleteSiteDomainAliasInfo(deleteAlias); return(deleteAlias != null); }
/// <inheritdoc/> public void RemoveSiteDomainAlias(ISite site, string aliasName) { // Gets the site object SiteInfo siteToWork = SiteInfoProvider.GetSiteInfo(site.SiteName); if (siteToWork != null) { // Gets the specified domain alias for the site SiteDomainAliasInfo deleteAlias = SiteDomainAliasInfoProvider.GetSiteDomainAliasInfo(aliasName, siteToWork.SiteID); // Deletes the site domain alias SiteDomainAliasInfoProvider.DeleteSiteDomainAliasInfo(deleteAlias); } }
/// <summary> /// Handle OnBeforeSave event of the UI form. /// </summary> /// <param name="sender">Sender object</param> /// <param name="e">Event argument</param> protected void Control_OnBeforeSave(object sender, EventArgs e) { if (siteInfo == null) { return; } if (!Control.IsInsertMode) { // Stop the site before saving the domain alias if (siteInfo.Status == SiteStatusEnum.Running) { SiteInfoProvider.StopSite(siteInfo.SiteName); siteInfo.Status = SiteStatusEnum.Stopped; runAfterSave = true; } } // Remove protocol from the domain alias string newDomainName = ValidationHelper.GetString(Control.Data["SiteDomainAliasName"], String.Empty); newDomainName = URLHelper.RemoveProtocol(newDomainName); Control.Data["SiteDomainAliasName"] = newDomainName.Trim(); // Ensure uniqueness of the domain name if (Control.IsInsertMode) { // Check duplicity if (SiteDomainAliasInfoProvider.DomainAliasExists(newDomainName, siteInfo.SiteID)) { Control.StopProcessing = true; Control.ShowError(ResHelper.GetString("Site_Edit.AliasExists")); } } else { // Check duplicity SiteDomainAliasInfo existing = SiteDomainAliasInfoProvider.GetSiteDomainAliasInfo(newDomainName, siteInfo.SiteID); if ((existing != null) && (existing.SiteDomainAliasID != domainInfo.SiteDomainAliasID)) { Control.StopProcessing = true; Control.ShowError(ResHelper.GetString("Site_Edit.AliasExists")); } } }
/// <summary> /// Deletes site domain alias. Called when the "Delete alias" button is pressed. /// Expects the CreateSiteDomainAlias method to be run first. /// </summary> private bool DeleteSiteDomainAlias() { // Get the site object SiteInfo site = SiteInfoProvider.GetSiteInfo("MyNewSite"); if (site != null) { // Get the site domain alias SiteDomainAliasInfo deleteAlias = SiteDomainAliasInfoProvider.GetSiteDomainAliasInfo("127.0.0.1", site.SiteID); // Delete the site domain alias SiteDomainAliasInfoProvider.DeleteSiteDomainAliasInfo(deleteAlias); return(deleteAlias != null); } return(false); }
/// <summary> /// Save or update domain alias. /// </summary> protected void btnOk_Click(object sender, EventArgs e) { string result = new Validator().NotEmpty(txtDomainName.Text, GetString("Site_Edit.AliasRequired")).Result; if (result == "") { // Check site of this domain alias if (si == null) { return; } // Stop the site before adding alias bool wasRunning = false; if (si.Status == SiteStatusEnum.Running) { SiteInfoProvider.StopSite(si.SiteName); si.Status = SiteStatusEnum.Stopped; wasRunning = true; } string redirect = String.Empty; // Correct domain name and return it to textbox txtDomainName.Text = URLHelper.RemoveProtocol(txtDomainName.Text); // Insert new if (alias == null) { // Check duplicity if (!SiteDomainAliasInfoProvider.DomainAliasExists(txtDomainName.Text, siteId)) { SiteDomainAliasInfo sdai = new SiteDomainAliasInfo(); sdai.SiteID = si.SiteID; sdai.SiteDomainAliasName = txtDomainName.Text.Trim(); sdai.SiteDefaultVisitorCulture = ValidationHelper.GetString(cultureSelector.Value, ""); sdai.SiteDomainDefaultAliasPath = pageSelector.Value.ToString().Trim(); sdai.SiteDomainRedirectUrl = txtRedirectUrl.Text.Trim(); SiteDomainAliasInfoProvider.SetSiteDomainAliasInfo(sdai); redirect = "Site_Edit_DomainAlias_Edit.aspx?siteId=" + sdai.SiteID + "&domainaliasid=" + sdai.SiteDomainAliasID + "&saved=1"; } else { ShowError(GetString("Site_Edit.AliasExists")); } } // Update else { // Check duplicity SiteDomainAliasInfo existing = SiteDomainAliasInfoProvider.GetSiteDomainAliasInfo(txtDomainName.Text, siteId); if ((existing == null) || (existing.SiteDomainAliasID == alias.SiteDomainAliasID)) { string originalDomainAlias = alias.SiteDomainAliasName; alias.SiteDomainAliasName = txtDomainName.Text.Trim(); alias.SiteDefaultVisitorCulture = ValidationHelper.GetString(cultureSelector.Value, ""); alias.SiteDomainDefaultAliasPath = pageSelector.Value.ToString().Trim(); alias.SiteDomainRedirectUrl = txtRedirectUrl.Text.Trim(); SiteDomainAliasInfoProvider.SetSiteDomainAliasInfo(alias, originalDomainAlias); // Update breadcrumbs CurrentMaster.Title.Breadcrumbs[1, 0] = alias.SiteDomainAliasName; ShowChangesSaved(); } else { ShowError(GetString("Site_Edit.AliasExists")); } } // Run site again if (wasRunning) { DataSet ds = SiteInfoProvider.CheckDomainNameForCollision(txtDomainName.Text.Trim(), si.SiteID); if (!DataHelper.DataSourceIsEmpty(ds)) { SiteInfo runningsi = SiteInfoProvider.GetSiteInfo(ValidationHelper.GetInteger(ds.Tables[0].Rows[0]["SiteID"], 0)); if (runningsi != null) { string collisionSite = runningsi.DisplayName; string collisionDomain = ValidationHelper.GetString(ds.Tables[0].Rows[0]["SiteDomainAliasName"], ""); if (String.IsNullOrEmpty(redirect)) { redirect = "Site_Edit_DomainAlias_Edit.aspx?siteId=" + alias.SiteID + "&domainaliasid=" + alias.SiteDomainAliasID + "&saved=1"; } // Add parameter indicating run problem redirect = URLHelper.AddParameterToUrl(redirect, "runerror", collisionSite + ";" + collisionDomain); } } else { // Seems to be ok, run the site try { SiteInfoProvider.RunSite(si.SiteName); } catch (Exception ex) { ShowError(ex.Message); redirect = ""; } } } // Redirect if (redirect != "") { URLHelper.Redirect(redirect); } } else { ShowError(result); } }