title: How to persist logged in user data for entire session?
body: <p>I'm creating a practice admin application using MVC4, but I'm not sure the best method to persist the logged in user data for the entire lifetime of the session so that it will be accessible to all views &amp; controllers.</p>
  
  <p>For example, I desire a user to log in, then download the user data from the database, and for the entire session I want to maintain the User model (Name, Database ID etc) so that it's accessible throughout the entire web application until the user is logged out.</p>
  
  <p>Is the best approach to store this data in an encrypted cookie? Or is there a way of using a Static Class?</p>
  
  <p>Currently I've read about using ViewModel Base class like so:</p>
  
  <pre><code>    public abstract class ViewModelBase
      {
          public UserModel User { get; set; }
      }
  </code></pre>
  
  <p>Then all of my ViewModels can inherit the base class, thus providing access to the user data model:</p>
  
  <pre><code>public class AllEmployeesViewModel : ViewModelBase
  {
      public List&lt;EmployeeModel&gt; Employees { get; set; } 
  }
  </code></pre>
  
  <p>However, if in one Controller action I set the user data, it will only be lost when loading another Controller Action.</p>
  
  <p>To me it seems a waste of resources &amp; will increase load times to have to keep downloading the user data from the database in every action.</p>
  
  <p>All advice is much welcome for this new web programmer. If I've missed any important details, please do request it and I will try my best to answer.</p>