Exam Area: Area 2 – Installation, Operation & Configuration (20%)
DXP integrates Azure CDN for static assets and optionally full-page caching.
| Type | Description |
|---|---|
| Static CDN | CSS, JS, images from the /Static/ folder |
| Blob CDN | Media from Azure Blob Storage |
| Full-page CDN | HTML pages (optional, requires setup) |
// Program.cs - Configure static file caching
app.UseStaticFiles(new StaticFileOptions
{
OnPrepareResponse = ctx =>
{
ctx.Context.Response.Headers.Add(
"Cache-Control",
"public, max-age=31536000"); // 1 year
}
});
// Blob media served via a CDN URL
// appsettings.json:
{
"EPiServer": {
"CmsAzureBlobStorageProvider": {
"ConnectionString": "...",
"ContainerName": "mysitemedia",
"CdnEndpoint": "https://mysite.azureedge.net" // CDN endpoint
}
}
}
// Purge CDN cache when content is published
[InitializableModule]
public class CdnCachePurgeModule : IInitializableModule
{
private IContentEvents _events;
public void Initialize(InitializationEngine context)
{
_events = context.Locate.Advanced.GetInstance<IContentEvents>();
_events.PublishedContent += OnPublished;
}
public void Uninitialize(InitializationEngine context)
{
_events.PublishedContent -= OnPublished;
}
private async void OnPublished(object sender, ContentEventArgs e)
{
// Get page URL
var urlResolver = ServiceLocator.Current.GetInstance<IUrlResolver>();
var url = urlResolver.GetUrl(e.ContentLink);
// Purge from CDN
await CdnService.PurgeAsync(url);
}
}
PaaS Portal → Environment → CDN
→ Enable/Disable CDN
→ CDN endpoint URL
→ Purge cache (manual)
→ Cache rules
// Controller-level caching
[ResponseCache(Duration = 3600, Location = ResponseCacheLocation.Any)]
public class StaticContentController : PageController<StaticPage>
{
public ActionResult Index(StaticPage currentPage)
{
return View(currentPage);
}
}
// Disable caching (for personalized content)
[ResponseCache(NoStore = true, Location = ResponseCacheLocation.None)]
public class PersonalizedController : PageController<PersonalizedPage> { }