📚 Product Knowledge
Website Configuration
📖 Docs

Website Configuration - Optimizely CMS 12

Exam Area: Area 1 – Product Knowledge (15%) Reference: https://docs.developers.optimizely.com/content-management-system/docs/sites


1. What is Website Configuration?

In CMS 12, a site is defined by a SiteDefinition object. Multiple sites can be hosted from a single CMS installation (multi-site). Each site has:


2. SiteDefinition Class

public class SiteDefinition
{
    public Guid             Id          { get; set; }  // Unique identifier
    public string           Name        { get; set; }  // "My Site"
    public Uri              SiteUrl     { get; set; }  // "https://www.mysite.com/"
    public ContentReference StartPage   { get; set; }  // Root page ContentReference
    public IList<SiteHost>  Hosts       { get; set; }  // Host bindings
}

3. SiteHost Class

public class SiteHost
{
    public string              Name     { get; set; }  // "www.mysite.com"
    public CultureInfo         Language { get; set; }  // null = all languages
    public HostDefinitionType  Type     { get; set; }  // Primary / Edit / Undecided
    public bool                UseSecureConnection { get; set; }  // https
}

HostDefinitionType:

ValueDescription
PrimaryMain/canonical URL for this host/language combination
EditUsed only for CMS Edit View access
UndecidedCatch-all — matches any host not explicitly bound
RedirectPermanent301 redirect to primary
RedirectTemporary302 redirect to primary

4. Admin UI – Website Configuration

/episerver/cms/admin → Websites
  → Add Website button
  → Select Start Page (content reference to root page)
  → Add Hosts:
       Hostname: www.mysite.com
       Type: Primary
       Language: (leave blank for all languages)

5. Multi-language Host Mapping

Map specific hostnames to specific languages:

www.mysite.com      → English (en)   [Primary]
www.mysite.se       → Swedish (sv)   [Primary]
www.mysite.de       → German (de)    [Primary]
cms.mysite.com      → (Edit)
*.mysite.com        → (Undecided — catch-all)

6. ISiteDefinitionRepository (Code Access)

public class SiteService
{
    private readonly ISiteDefinitionRepository _siteRepo;

    public SiteService(ISiteDefinitionRepository siteRepo)
    {
        _siteRepo = siteRepo;
    }

    // Get all sites
    public IEnumerable<SiteDefinition> GetAll() => _siteRepo.List();

    // Get current site (based on HTTP request host)
    public SiteDefinition Current => SiteDefinition.Current;

    // Create a new site
    public void CreateSite(string name, ContentReference startPage, Uri primaryUrl)
    {
        var site = new SiteDefinition
        {
            Name      = name,
            SiteUrl   = primaryUrl,
            StartPage = startPage,
            Hosts = new List<SiteHost>
            {
                new SiteHost
                {
                    Name     = primaryUrl.Host,
                    Type     = HostDefinitionType.Primary,
                    Language = CultureInfo.GetCultureInfo("en")
                }
            }
        };
        _siteRepo.Save(site);
    }
}

7. SiteDefinition.Current

// Static accessor — resolves the current site from the HTTP request context
var currentSite     = SiteDefinition.Current;
var startPageRef    = currentSite.StartPage;
var siteUrl         = currentSite.SiteUrl;
var siteName        = currentSite.Name;

8. Configuration in appsettings.json

{
  "EPiServer": {
    "CMS": {
      "SitePath": "/",
      "UIUrl": "/episerver/cms"
    }
  }
}

9. Multi-site Routing

When a request comes in:

  1. CMS matches the Host header against all registered SiteHost entries
  2. Finds the matching SiteDefinition
  3. Resolves the correct start page for that site
  4. Routes the URL relative to that start page

Review Questions

  1. What class defines a site in CMS 12? (SiteDefinition)
  2. What does HostDefinitionType.Edit mean? (This hostname is used for CMS Edit View access)
  3. How do you get the current site in code? (SiteDefinition.Current)
  4. What does HostDefinitionType.Undecided mean? (Catch-all — matches any hostname not explicitly bound)
  5. Which interface is used to save/retrieve site definitions from the database? (ISiteDefinitionRepository)