7

Fairly sure I can guess the answer, but getting this question on record is still useful. Long story short:

Can I use config patch files to manage configuration settings on my Sitecore IS web application?

We are about to add Azure AD integration to our solution and, for this, some configuration changes are required to our base IS setup.

Do I do this by modifying the OOTB configuration files directly, or can I leave those as-is and "patch" in my required changes?

2 Answers 2

8

Sitecore Host (the platform Sitecore Identity is built on) does have a "patching" mechanism for configuration files that is an extension of the default ASP.NET Core configuration builder.

When a Sitecore Host application such is Sitecore Identity runs, Sitecore Host performs a merge of all of the .xml configuration files in the various folders in the application. Sitecore has provided a diagram showing the order in which values are determined:

Sitecore Host configuration load order

This configuration merge process happens at application initialization, so any configuration value defined in an .xml file could be overridden at the command line or through environment variables.

An example of how the merge process works is shown below. You'll notice that the <Debug> and <Root> values are both in the merged configuration and since File2.xml is the one that takes precedence, <MyValue> contains the value of what is in File2.xml

File1.xml

<Settings>
  <Sitecore>
    <Diagnostics>
      <Debug>true</Debug>
      <MyValue>First</MyValue>
    </Diagnostics>
  </Sitecore>
</Settings>

File2.xml

<Settings>
  <Sitecore>
    <Diagnostics>
      <Root>Alt</Root>
      <MyValue>Second</MyValue>
    </Diagnostics>
  </Sitecore>
</Settings>

Merged configuration

<Settings>
  <Sitecore>
    <Diagnostics>
      <Debug>true</Debug>
      <Root>Alt</Root>
      <MyValue>Second</MyValue>
    </Diagnostics>
  </Sitecore>
</Settings>

As a best practice, all custom .xml config files should be placed in the sitecoreruntime folder. Any configuration in the sitecoreruntime folder will take precedence over any other config file (with the exception of command line overrides and environment variables).

In addition, you can use Sitecore-style configuration patching syntax such as patch:before, patch:after, etc. to patch specific values. A sample is shown below:

<Settings>
  <Sitecore xmlns:patch="http://www.sitecore.net/xmlconfig/">
     <sites>
      <site patch:before="*[@name='website']" name="mysite" />
      <site patch:after="*[@name='website']" name="mysite2" />
      <site patch:delete="*[@name='website']" name="mysite2" />
      <site patch:instead="*[@name='website']" name="mysite2" />
      <patch:attribute name="value">
       MyNewValue
      </patch:attribute>
    </sites>
  </Sitecore>
</Settings>

Once you have your values patched as you need it, you can access the final merged/patched configuration from the injected ISitecoreConfiguration object.

_Source: https://doc.sitecore.com/developers/92/sitecore-experience-management/en/configuration.html

2

Identity Server uses Sitecore Host which does support patching. Surprise!

https://doc.sitecore.com/developers/91/sitecore-experience-management/en/configuration.html

But if you're doing an Azure AD integration, Sitecore provides a plugin out of the box for that and you can either modify that config directly or patch yours in. In your Identity Server folder, look under \sitecore\Sitecore.Plugin.IdentityProvider.AzureAd\Config for the config.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.