title: How to dynamically change connection string ASP.NET
body: <p>I'm developing an application that relies on ASP.NET C# for the back-end. I'm trying to change the connection string on the controller depending on what's coming from the request.</p>
  <p>Example:</p>
  <p>POST 1: access to server 10.126.0.1 db: db_manager</p>
  <p>POST 2: access to server 10.126.0.2 db: bd2_manager</p>
  <p>The ip and db are supposed to be input to the request and change it accordingly.</p>
  <p>I'm currently defining the connection string in the <code>Startup.cs</code> (<code>ConfigureServices</code> method) file like this:</p>
  <pre><code> string connectionString = Configuration.GetConnectionString(&quot;connection&quot;);
  
              services.AddSingleton&lt;INHibernateSessionFactory&gt;(provider =&gt; new NHibernateSessionFactory(connectionString));
              services.AddScoped(provider =&gt; provider.GetRequiredService&lt;INHibernateSessionFactory&gt;().OpenSession());
              services.AddScoped&lt;IDataContext, DataContext&gt;();
  </code></pre>
  <p>I'd like to know how can I define and change the <code>connectionString</code> dynamically for the duration of the request, instead of statically in the startup.</p>