Exam Area: Area 1 – Product Knowledge (15%) Reference: https://docs.developers.optimizely.com/content-management-system/docs/sites
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:
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
}
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:
| Value | Description |
|---|---|
Primary | Main/canonical URL for this host/language combination |
Edit | Used only for CMS Edit View access |
Undecided | Catch-all — matches any host not explicitly bound |
RedirectPermanent | 301 redirect to primary |
RedirectTemporary | 302 redirect to primary |
/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)
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)
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);
}
}
// 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;
{
"EPiServer": {
"CMS": {
"SitePath": "/",
"UIUrl": "/episerver/cms"
}
}
}
When a request comes in:
Host header against all registered SiteHost entriesSiteDefinitionHostDefinitionType.Edit mean? (This hostname is used for CMS Edit View access)HostDefinitionType.Undecided mean? (Catch-all — matches any hostname not explicitly bound)