/// <inheritdoc/>
        public IEnumerable <ISiteDomainAlias> GetDomainAliases(ISite site)
        {
            List <ISiteDomainAlias> aliases = new List <ISiteDomainAlias>();

            // Gets the site object
            SiteInfo siteToWork = SiteInfoProvider.GetSiteInfo(site.SiteName);

            if (siteToWork != null)
            {
                // Gets all the domain alias for the site
                var items = SiteDomainAliasInfoProvider.GetDomainAliases(site.SiteName)?.Items;

                foreach (var item in items)
                {
                    aliases.Add(item.ActLike <ISiteDomainAlias>());
                }
            }

            return(aliases);
        }
Exemple #2
0
    /// <summary>
    /// Button Ok click.
    /// </summary>
    /// <param name="sender">Sender</param>
    /// <param name="e">Arguments</param>
    protected void btnOk_Click(object sender, EventArgs e)
    {
        // Validate file name
        string fileName     = txtFileName.Text.Trim();
        string errorMessage = new Validator().NotEmpty(fileName, GetString("lincense.export.filenameempty")).IsFileName(fileName, GetString("license.export.notvalidfilename")).Result;

        if (!string.IsNullOrEmpty(errorMessage))
        {
            ShowError(errorMessage);
        }
        else
        {
            try
            {
                // Create writers
                string path = ImportExportHelper.GetSiteUtilsFolder() + "Export\\" + fileName;
                DirectoryHelper.EnsureDiskPath(path, SettingsKeyProvider.WebApplicationPhysicalPath);

                using (FileStream file = FileStream.New(path, FileMode.Create))
                {
                    using (StreamWriter sw = StreamWriter.New(file))
                    {
                        // Array list for duplicity checking
                        ArrayList allSites = new ArrayList();

                        // Get all sites
                        DataSet sites = SiteInfoProvider.GetSites(null, null, "SiteID,SiteDomainName");
                        if (!DataHelper.DataSourceIsEmpty(sites))
                        {
                            foreach (DataRow dr in sites.Tables[0].Rows)
                            {
                                // Get domain
                                string domain = ValidationHelper.GetString(dr["SiteDomainName"], "");
                                if (!string.IsNullOrEmpty(domain))
                                {
                                    domain = GetDomain(domain);
                                    // Add to file
                                    if (!allSites.Contains(domain))
                                    {
                                        sw.WriteLine(domain);
                                        allSites.Add(domain);
                                    }

                                    // Add all domain aliases
                                    DataSet aliases = SiteDomainAliasInfoProvider.GetDomainAliases("SiteID=" + ValidationHelper.GetString(dr["SiteID"], ""), null, "SiteDomainAliasName");
                                    if (!DataHelper.DataSourceIsEmpty(aliases))
                                    {
                                        foreach (DataRow drAlias in aliases.Tables[0].Rows)
                                        {
                                            // Get domain
                                            domain = ValidationHelper.GetString(drAlias["SiteDomainAliasName"], "");
                                            if (!string.IsNullOrEmpty(domain))
                                            {
                                                domain = GetDomain(domain);
                                                // Add to file
                                                if (!allSites.Contains(domain))
                                                {
                                                    sw.WriteLine(domain);
                                                    allSites.Add(domain);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                // Output
                string downloadPath = ImportExportHelper.GetSiteUtilsFolderRelativePath();
                string location     = null;

                // Path is relative path
                if (downloadPath != null)
                {
                    string externalUrl = null;
                    string fullPath    = downloadPath + "Export/" + fileName;

                    // Handle external storage URL
                    if (StorageHelper.IsExternalStorage(fullPath))
                    {
                        externalUrl = File.GetFileUrl(fullPath, CMSContext.CurrentSiteName);
                    }

                    // Handle default URL
                    if (string.IsNullOrEmpty(externalUrl))
                    {
                        location = URLHelper.ResolveUrl(downloadPath + "Export/" + fileName);
                    }
                    else
                    {
                        location = externalUrl;
                    }

                    location = String.Format("<a href=\"{0}\" target=\"_blank\">{0}</a>", location);
                }
                else
                {
                    location = "<b>" + path + "</b>";
                }

                ShowConfirmation(GetString("license.export.exported"));
                ShowInformation(String.Format(GetString("license.export.download"), location));

                plcTextBox.Visible = false;
            }
            catch (Exception ex)
            {
                ShowError(ex.Message);
            }
        }
    }
    /// <summary>
    /// Button Ok click.
    /// </summary>
    /// <param name="sender">Sender</param>
    /// <param name="e">Arguments</param>
    protected void btnOk_Click(object sender, EventArgs e)
    {
        // Validate file name
        string fileName     = txtFileName.Text.Trim();
        string errorMessage = new Validator().NotEmpty(fileName, GetString("lincense.export.filenameempty")).IsFileName(fileName, GetString("license.export.notvalidfilename")).Result;

        if (!string.IsNullOrEmpty(errorMessage))
        {
            ShowError(errorMessage);
        }
        else
        {
            try
            {
                // Create writers
                string path = ImportExportHelper.GetSiteUtilsFolder() + "Export\\" + fileName;
                DirectoryHelper.EnsureDiskPath(path, SystemContext.WebApplicationPhysicalPath);

                using (FileStream file = FileStream.New(path, FileMode.Create))
                {
                    using (StreamWriter sw = StreamWriter.New(file))
                    {
                        // Array list for duplicity checking
                        ArrayList allSites = new ArrayList();

                        // Get all sites
                        DataSet sites = SiteInfoProvider.GetSites().Columns("SiteID,SiteDomainName");
                        if (!DataHelper.DataSourceIsEmpty(sites))
                        {
                            foreach (DataRow dr in sites.Tables[0].Rows)
                            {
                                // Get domain
                                string domain = ValidationHelper.GetString(dr["SiteDomainName"], "");
                                if (!string.IsNullOrEmpty(domain))
                                {
                                    domain = GetDomain(domain);
                                    // Add to file
                                    if (!allSites.Contains(domain))
                                    {
                                        sw.WriteLine(domain);
                                        allSites.Add(domain);
                                    }

                                    // Add all domain aliases
                                    DataSet aliases = SiteDomainAliasInfoProvider.GetDomainAliases()
                                                      .Column("SiteDomainAliasName")
                                                      .Where("SiteID", QueryOperator.Equals, ValidationHelper.GetInteger(dr["SiteID"], 0));

                                    if (!DataHelper.DataSourceIsEmpty(aliases))
                                    {
                                        foreach (DataRow drAlias in aliases.Tables[0].Rows)
                                        {
                                            // Get domain
                                            domain = ValidationHelper.GetString(drAlias["SiteDomainAliasName"], "");
                                            if (!string.IsNullOrEmpty(domain))
                                            {
                                                domain = GetDomain(domain);
                                                // Add to file
                                                if (!allSites.Contains(domain))
                                                {
                                                    sw.WriteLine(domain);
                                                    allSites.Add(domain);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                // Output
                string url          = ImportExportHelper.GetExportPackageUrl(fileName, SiteContext.CurrentSiteName);
                string downloadLink = (url != null) ? String.Format("<a href=\"{0}\" target=\"_blank\">{1}</a>", url, GetString("license.export.clicktodownload")) : "";
                string storageName  = (StorageHelper.IsExternalStorage(path)) ? GetString("Export.StorageProviderName." + StorageHelper.GetStorageProvider(path).Name) : "";
                string relativePath = ImportExportHelper.GetSiteUtilsFolderRelativePath() + "Export/" + txtFileName.Text;

                ShowConfirmation(GetString("license.export.exported"));
                ShowInformation(String.Format(GetString("license.export.download"), storageName, relativePath, downloadLink));

                plcTextBox.Visible = false;
            }
            catch (Exception ex)
            {
                ShowError(ex.Message);
            }
        }
    }
Exemple #4
0
        private void Begin_Execute(object sender, EventArgs e)
        {
            string url     = RequestContext.CurrentRelativePath + RequestContext.CurrentQueryString;
            string handler = url.Split('/')[1].ToLower();

            string[] notwanted = { "cmspages", "cmsmodules", "cmsformcontrols", "cmsadmincontrols", "admin", "getattachment", "getfile", "getmedia", "getmetafile", "app_themes", "cmsapi", "socialmediaapi", "searchapi", "formsapi", "api" };

            // only run this code if we need to perform a redirect
            if (!notwanted.Contains(handler) && SiteContext.CurrentSite != null)
            {
                var currentSite      = SiteContext.CurrentSite;
                var dictCultureAlias = CacheHelper.GetItem($"RedirectionHandler_CultureAliasDictionary_{currentSite.SiteName}") as Dictionary <string, string>;

                if (dictCultureAlias == null)
                {
                    dictCultureAlias = new Dictionary <string, string>();
                    var domainAliasDict = new Dictionary <string, string>();

                    var primaryAliasInfo = new SiteDomainAliasInfo();
                    primaryAliasInfo.SiteDomainAliasName       = currentSite.DomainName;
                    primaryAliasInfo.SiteDefaultVisitorCulture = currentSite.DefaultVisitorCulture;

                    var domainAliases = SiteDomainAliasInfoProvider.GetDomainAliases().Columns("SiteID", "SiteDomainAliasName", "SiteDefaultVisitorCulture").Where(x => x.SiteID == currentSite.SiteID).ToList();
                    if (domainAliases != null)
                    {
                        domainAliases.Add(primaryAliasInfo);
                        var cultureBindings = CultureSiteInfoProvider.GetCultureSites().WhereEquals("SiteID", SiteContext.CurrentSiteID);
                        foreach (var cultureBinding in cultureBindings)
                        {
                            var culture = CultureInfoProvider.GetCultureInfo(cultureBinding.CultureID);
                            if (culture != null)
                            {
                                if (String.IsNullOrEmpty(culture.CultureAlias))
                                {
                                    var domainAlias = domainAliases.Where(x => x.SiteDefaultVisitorCulture == culture.CultureCode).FirstOrDefault();
                                    if (domainAlias != null)
                                    {
                                        dictCultureAlias.Add(culture.CultureCode, "domain");
                                    }
                                }
                                else
                                {
                                    dictCultureAlias.Add(culture.CultureCode, culture.CultureAlias);
                                }
                            }
                        }
                    }
                    CacheHelper.Add("RedirectionHandler_CultureAliasDictionary", dictCultureAlias, null, DateTime.Now.AddHours(72), System.Web.Caching.Cache.NoSlidingExpiration);
                }

                var currentCulture = LocalizationContext.CurrentCulture.CultureCode;

                //Not sure if this is a Kentico bug or not, but LocalizationContext.CurrentCulture.CultureCode sometimes does not actually show the current user's culture
                //This usually happens if this is the first request by a user on a new culture. Comparing it to the cookie value of the user always shows the correct culture
                if (!String.IsNullOrEmpty(CookieHelper.GetValue("CMSPreferredCulture")) && CookieHelper.GetValue("CMSPreferredCulture") != currentCulture)
                {
                    currentCulture = CookieHelper.GetValue("CMSPreferredCulture");
                }

                if (dictCultureAlias.ContainsKey(currentCulture))
                {
                    //Handle Redirect
                    try
                    {
                        int site         = SiteContext.CurrentSiteID;
                        var cultureCode  = currentCulture;
                        var cultureAlias = dictCultureAlias[cultureCode];

                        // make sure the culture has been set for the site
                        URLRedirectionMethods.Redirect(url, site, cultureCode, cultureAlias);
                    }
                    catch (ThreadAbortException threadEx)
                    {
                        //Do nothing: this exception is thrown by Response.Redirect() in the redirect method. We only want to log other kinds of exceptions
                    }
                    catch (Exception ex)
                    {
                        EventLogProvider.LogException("RedirectionMethods.Redirect", "REDIRECT_FAILED", ex, additionalMessage: "An exception occurred during the redirect process");
                    }
                }
                else
                {
                    EventLogProvider.LogInformation("UrlRedirection.RedirectionHandler.Begin_Execute", "REDIRECT_FAILED", $"The culture code: {LocalizationContext.CurrentCulture.CultureCode} was not assigned to the site. Unable to redirect URL: {RequestContext.RawURL}");
                }
            }
        }