We have a requirement to store all the secrets on to azure key-vault. This requires us to update the configurations at Runtime.

One challenge we are facing at the moment is to store the password for SOLR basic auth on to azure key-vault.

        <solrHttpWebRequestFactory type="HttpWebAdapters.HttpWebRequestFactory, SolrNet">
        <solrHttpWebRequestFactory type="HttpWebAdapters.BasicAuthHttpWebRequestFactory, SolrNet">
          <param hint="username">username</param>
          <param hint="password">password</param>

We managed to read and update the asp.net connection strings and web.config. However not for sitecore configs.


Is there a way (any sitecore API) which we could use to update the sitecore configurations at runtime?


2 Answers 2


No, you cannot update Sitecore configuration in a runtime (all configs are parsed into one big config on application start).

I would go with different approach then.

Find HttpWebAdapters.BasicAuthHttpWebRequestFactory class in SolrNet.dll and see how it works. Overwrite this class or write your own (must implement IHttpWebRequestFactory interface).

Inside that class, instead of taking password and login from configuration fetch it from different source (that can be changed during a runtime, the simplest case would be a txt file stored somewhere. Remember that the file has to be protected and cannot be accessible publicly).

Once you have your class with custom code, patch solrHttpWebRequestFactory node with your custom type.


You can customize configuration by overriding the default ConfigReader defined in web.config. For example:

<?xml version="1.0" encoding="utf-8"?>
    <!-- Insert custom ConfigReader class here -->
    <section name="sitecore" type="MyProject.CustomConfigReader, MyProject" />
    <!-- ... -->
  <!-- ... -->

Then for your custom config reader, override the default one and add your patching logic after the default patching code is done:

namespace MyProject
  public class CustomConfigReader : Sitecore.Configuration.ConfigReader
    protected override void LoadAutoIncludeFiles(System.Xml.XmlNode element)

    protected virtual void PatchSolrCredentials(Sitecore.Configuration.ConfigPatcher patcher)
      // You could also edit the XML nodes directly in patcher.Document.
      var patch = @"<configuration xmlns:patch='http://www.sitecore.net/xmlconfig/'>
                  <param hint='username'>username</param>
                  <param hint='password'>password</param>
      // (Replace with username and password from key vault)
      var reader = new System.IO.StringReader(patch);

Here are a couple of other interesting examples of using a custom ConfigReader:

  • Didn't work as congig reader loads begore our services ehivh gets secret from keyvault
    – Nil Pun
    Commented Mar 29, 2017 at 11:13

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.