Welcome to the navigation

Dolor veniam, in ut enim qui ipsum aliqua, nisi amet, duis labore irure magna laboris exercitation velit in ut esse est eiusmod dolore non sunt. Dolor elit, eu proident, laborum, minim sit dolor occaecat aliquip pariatur, do laboris consequat, voluptate fugiat non dolore lorem ullamco ipsum reprehenderit cillum est enim

Yeah, this will be replaced... But please enjoy the search!

Programmatically rewriting all site and host definitions to HTTPS in Optimizely CMS

Some sites have many host definitions, and some want's to enforce HTTPS within Optimizely CMS.

There are various way to ensure this, this is a routine I wrote to convert all site and host definitions to use HTTPS, except the wildcard host

// ISiteDefinitionRepository siteDefinitionRepository

var sites = _siteDefinitionRepository.List();

foreach (var site in sites)
{
    var writableSite = site.CreateWritableClone();

    if (site.SiteUrl.Scheme == "http")
    {
        writableSite.SiteUrl = new Uri(site.SiteUrl.ToString().Replace("http", "https"));
    }

    var hosts = writableSite.Hosts.Where(x => !x.Name.Equals(HostDefinition.WildcardHostName)); 

    foreach (var writableHost in hosts)
    {
        writableHost.UseSecureConnection = true;
    }

    _siteDefinitionRepository.Save(writableSite);
}

This will turn this

Into this