title: Set HttpContext.User for the session
body: <p>I've implemented custom authentication in ASP.NET MVC. If a valid user tries to login, I set the <code>HttpContext.User = user</code> in the Logon method of the AccountController. But it remains there for only <em>that request</em>. How can I set it for the session?</p>
  
  <p>I used an alternative, set <code>HttpContext.Session["CurrentUser"] = user</code>. If I want to see if the session is authorized, I'd have to check that the <code>HttpContext.User != null</code>. But, I don't want to expose the authentication logic everywhere in the application. If I need to change that, it'd be messy.</p>
  
  <p>Please help me solve this. One solution could be populating the <code>HttpContext.User</code> property of every request with the value of <code>HttpContext.Session["CurrentUser"]</code> at the beginning, but I don't know how to do it.</p>