title: I want to use session in the asp.net mvc controller constructor
body: <p>I'm new to Mvc.</p>
  
  <p>Sorry to my english. ^^</p>
  
  <p>I have some question about asp.net MVC session in the controller.</p>
  
  <p>The Scenario things that I want to do is like follows..</p>
  
  <ol>
  <li><p>First of all, My development circumstance is entityframework and mvc3.</p></li>
  <li><p>When Someone logged in each one has different database. So, Each has connect different database.</p></li>
  <li><p>So, Each person has his own session value which is database connection string. So far so good.</p></li>
  <li><p>I have simple database Repository and at the each repository's constructor can change database connection.</p></li>
  <li><p>At controller which calls Repository class, I need session value. But As I know Controller's construction can't keep session value. right?</p></li>
  <li><p>I want your good advice. Thanks in advance.</p></li>
  </ol>
  
  <p>Code samples are below:</p>
  
  <pre><code>public class MasterRepository 
  {
      DBEntities _db;
  
      public MasterRepository(string con)
      {
          _db = new DBEntities(con);
      }
  
  }
  
  public class TestController : Controller
  {
  
      private string con;
  
      MasterRepository _db;
  
      public TestController()
      {
      _db = new MasterRepository(Session["conn"].ToString()); //  Session is null I want to solve this Part...
      }
  
      public ActionResult Index()
      {
  
          string con = Session["conn"].ToString(); // Session is assigned.
  
          return View();
      }
  
  
  }     
  </code></pre>