title: How to use custom httpcontext user when using custom Membership/Role Provider
body: <p>Hi guys so I'm using a custom membership provider and custom role provider. And it is logging in using these correctly. I also implemented my own Membership user object so that I can gain access to other user information, and I don't need to load all the data everytime I change page, but I currently cannot get this to work properly. Below is my user object:</p>
  
  <pre><code>public class User : MembershipUser
  {
      [Required(ErrorMessage = "Username cannot be blank")]
      [Display(Name = "User name")]
      public string UserName { get; set; }
  
      [Required(ErrorMessage = "Password cannot be blank")]
      [DataType(DataType.Password)]
      [Display(Name = "Password")]
      public string Password { get; set; }
  
      [Display(Name = "User ID")]
      public long UserID { get; set; }
  
      [Display(Name = "Family Name")]
      [StringLength(50, ErrorMessage = "Family name cannot be longer than 50 characters")]
      public string FamilyName { get; set; }
  
      [Display(Name = "Given Name")]
      [StringLength(50, ErrorMessage = "Given name cannot be longer than 50 characters")]
      public string GivenName { get; set; }
  
      public Company Company { get; set; }
  
      public virtual IIdentity Identity { get; set; }
  }
  </code></pre>
  
  <p>And when the user logs in I call the following login method:</p>
  
  <pre><code>    [AllowAnonymous]
      [HttpPost]
      public ActionResult Login(User model, string returnUrl)
      {
          FormsAuthentication.SignOut();
          if(Membership.ValidateUser(model.UserName, model.Password))
          {
              FormsAuthentication.SetAuthCookie(model.UserName, true);
              return RedirectToAction("Index", "");
          }
          ViewBag.Message = "Failed to login";
          return View();
      }
  </code></pre>
  
  <p>But when I call <code>HttpContext.User</code> in index it just contains name/ID, not the rest of my user object. Do I need to create a custom <code>FormAuthentication</code> object? Or is it standard process to store all this user information inside the <code>HttpContext.Session</code> object? Or get my user to extend the <code>System.Security.Principle.IPrinciple</code>? Or even in the <code>Controller.TempData</code>? Or somewhere else I'm not familiar with. I dont want to have to hit the database everytime to load the user data.</p>
  
  <p>Sorry if these are obvious questions I'm fairly new to web development and not sure what the generic way of doing these things are. Trying to use the in build Authorize attributes.</p>