Skip to content

Instantly share code, notes, and snippets.

{
"sitecore": {
"context": {
"pageEditing": false,
"language": "en",
"site": { "name": "my-site" }
},
"route": {
"name": "home",
"fields": {
var cacheDuration = Sitecore.Configuration.Settings.GetTimeSpanSetting("MyProject.Cache.Duration", TimeSpan.FromMinutes(30));
<!-- App_Config/Include/Project/Z.Project.Environment.config -->
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"
xmlns:role="http://www.sitecore.net/xmlconfig/role/"
xmlns:env="http://www.sitecore.net/xmlconfig/env/">
<sitecore>
<settings>
<!-- Applies to every CD server, regardless of environment -->
<setting name="MyProject.Analytics.Enabled" value="true"
role:require="ContentDelivery" />
<configSections>
<section name="sitecore" type="Sitecore.Configuration.RuleBasedConfigReader, Sitecore.Kernel" />
</configSections>
<sitecore configSource="App_Config\Sitecore.config" />
<!-- web.config on a CD server in the DEV environment -->
<appSettings>
<add key="role:define" value="ContentDelivery" />
<add key="env:define" value="DEV" />
</appSettings>
<setting name="MyFeature.CacheEnabled" value="true" role:require="ContentDelivery" />
<!-- web.config on a Content Delivery server -->
<appSettings>
<add key="role:define" value="ContentDelivery" />
</appSettings>
curl -I https://yoursite.com/~/media/Documents/Factsheet.ashx
private void SetAttachmentDisposition(HttpResponse response, string name, string extension)
{
    string filename = $"{name}.{extension}";
    string encoded = Uri.EscapeDataString(filename);
    response.Headers["Content-Disposition"] = $"attachment; filename=\"{filename}\"; filename*=UTF-8''{encoded}";
}
<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <mediaLibrary>
      <mediaProvider type="MyProject.Foundation.Media.CustomMediaProvider, MyProject.Foundation.Media" patch:instead="*[@type='Sitecore.Resources.Media.MediaProvider, Sitecore.Kernel']" />
    </mediaLibrary>
  </sitecore>
</configuration>