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);
}
}
}
<indexConfigurations>
<solrHttpWebRequestFactory type="HttpWebAdapters.HttpWebRequestFactory, SolrNet">
<patch:delete/>
</solrHttpWebRequestFactory>
<solrHttpWebRequestFactory type="MyClassLibrary.MyBasicAuthHttpWebRequestFactory, MyClassLibrary">
<param hint="username">
</param>
<param hint="password">
</param>
</solrHttpWebRequestFactory>
</indexConfigurations>