title: How to share Session value across multiple Controllers in MVC C#?
body: <p>Hello everyone I'm trying to share object values using Sessions across different controllers, I'm kind of lost because the way I handle authentication in my website is not described in any article nor guide I can refer to in order to follow up a "how-to"</p>
  
  <p>Anyways I have a BaseController that is shared among other Controllers that has the "BaseController.verifyAccess(string user, string password)", what it does is, it goes and check in my DB if the user has access to the View</p>
  
  <p><strong>BaseController.cs</strong></p>
  
  <pre><code>public class User
  {
      public int ID { get; set; }
      public string username { get; set; }
      public string password { get; set; }
      public string email { get; set; }
  }
  </code></pre>
  
  <p><strong>AccountController.cs</strong></p>
  
  <pre><code>[HttpPost]
  public ActionResult Login(FormCollection form)
  {
      User userTest = new User();
      userTest.username = form["username"];
      userTest.password = form["password"];
      Session["username"] = userTest.username;
  
      if (verifyAccess(userTest.username, userTest.password))
      {
          return RedirectToAction("../LoggedIn");
      }
      else
      {
          return RedirectToAction("../Login");
      }
  }
  </code></pre>
  
  <p>How can I get <code>Session["username"] = userTest.username;</code> to work in other Controllers??</p>
  
  <p>For example </p>
  
  <p><strong>SomeController.cs</strong></p>
  
  <pre><code>[HttpPost]
  public ActionResult MyAwesomeView(FormCollection form)
  {
      Project.Models.MyAwesomeModel thisModel = new Models.MyAwesomeModel();
      thisModel._info1 = form["txtInfo1"];
      thisModel._info2 = form["txtInfo2"];
      thisModel._info3 = form["txtInfo3"];
      thisModel._info4 = form["txtInfo4"];
      thisModel._user = System.Web.HttpContext.Current.Session["username"].ToString();
      return View(modelPagosRecibidos);
  }
  </code></pre>
  
  <p>While debugging <code>thisModel._user</code> is null, plus I think I'm doing this heavily wrong, I apologize if someone sighs at my code, anyways hope to get some help and guidance on how to get Session values across my Controllers, thanks in advance to everyone!</p>