I want to store Solr basic authentication credential in key vault and I want to achieve this by doing something like this.. however I tried using below code in application start but it seems it is not hooking properly , not sure what I m doing wrong here.

IHttpWebRequestFactory solrBasicAuthHttpWebRequestFactory = 
    new HttpWebAdapters.BasicAuthHttpWebRequestFactory("admin", "somepassword*");
solrBasicAuthHttpWebRequestFactory.Create(new Uri("localhost:8080/solr"));

I also got one reference to patch file using this custom config reader but I m trying to work it programmatically. Any help. Update sitecore configs at runtime

  • What version of Sitecore are you using? Mar 28, 2017 at 21:11
  • Sitecore version 8.2.1 Mar 28, 2017 at 22:44

1 Answer 1


We created a custom BasicAuthHttpWebRequest using the reference of the code from Solr.net and then referenced this class library in solr indexconfiguration section.

    namespace MyclassLibrary


public class MyBasicAuthHttpWebRequestFactory : IHttpWebRequestFactory { private readonly string username; private readonly string password;

public MyBasicAuthHttpWebRequestFactory(string username, string password)
{//This is where we can fetch credential from appsetting
  this.username = ConfigurationManager.AppSettings["UserName"];
  this.password =ConfigurationManager.AppSettings["password"];

public IHttpWebRequest Create(string url)
  return this.Create(new Uri(url));

public IHttpWebRequest Create(Uri url)
  HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url);
  string base64String = Convert.ToBase64String(Encoding.ASCII.GetBytes(this.username + ":" + this.password));
  request.Headers.Add("Authorization", "Basic " + base64String);
  return (IHttpWebRequest) new HttpWebRequestAdapter(request);

} }

    <solrHttpWebRequestFactory type="HttpWebAdapters.HttpWebRequestFactory, SolrNet">
    <solrHttpWebRequestFactory type="MyClassLibrary.MyBasicAuthHttpWebRequestFactory, MyClassLibrary">
      <param hint="username">
      <param hint="password">
  • This isn't working - I think you're missing the configurations needed in SOLR to secure the requests.
    – M.R.
    May 4, 2018 at 13:52

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.