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