I am creating a simple login using ASP.NET MVC4 / Razor. I need custom logic, so here's what I have so far:
public class User
   {
      [Required]
      [Display(Name = "User name")]
      public string UserName { get; set; }
      [Required]
      [DataType(DataType.Password)]
      [Display(Name = "Password")]
      public string Password { get; set; }
      public int UserID { get; set; }
      public DateTime LastLogin { get; set; }
      public bool IsValid(string username, string password)
      {
         if(MyCustomLogic.isValidUser(username, password)){
            // Set other variables
            return true;
         } else {
            return false;
         }
      }
   }
In the Controller:
public ActionResult Login(Models.User user)
{
   if (ModelState.IsValid)
   {
      if (user.IsValid(user.UserName, user.Password))
      {
         FormsAuthentication.SetAuthCookie(user.UserName, true);
         // This line is in question
      }
   }
   return View(user);
}
I want to store the Model.User so it can be accessed in the View persistently. Storing it in a Session variable seems to obvious choice, but that will expire independently of the Authentication Cookie.
 
     
    