예제 #1
0
        /// <inheritdoc/>
        public void AddSiteDomainAlias(ISite site, string aliasName)
        {
            // Gets the site object
            SiteInfo siteToWork = SiteInfoProvider.GetSiteInfo(site.SiteName);

            if (siteToWork != null)
            {
                // Creates a new site domain alias object
                SiteDomainAliasInfo newAlias = new SiteDomainAliasInfo
                {
                    SiteDomainAliasName = aliasName,

                    // Assigns the domain alias to the site
                    SiteID = siteToWork.SiteID,
                };

                // Saves the site domain alias to the database
                SiteDomainAliasInfoProvider.SetSiteDomainAliasInfo(newAlias);
            }
        }
예제 #2
0
    /// <summary>
    /// Creates site domain alias. Called when the "Create alias" button is pressed.
    /// </summary>
    private bool AddDomainAliasToSite()
    {
        // Get the site object
        SiteInfo site = SiteInfoProvider.GetSiteInfo("MyNewSite");

        if (site != null)
        {
            // Create new site domain alias object
            SiteDomainAliasInfo newAlias = new SiteDomainAliasInfo();

            // Set the properties
            newAlias.SiteDomainAliasName = "127.0.0.1";
            newAlias.SiteID = site.SiteID;

            // Save the site domain alias
            SiteDomainAliasInfoProvider.SetSiteDomainAliasInfo(newAlias);

            return(true);
        }

        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);
        }
    }