I think I have a simple question regarding authentication in asp.net mvc 4. One thing that isn't clear to me is I can add/serialize user data into the authorization cookie. What are the benefits/trade offs of putting the user data in the authentication cookie versus adding the user data to the session? Do I even need to put anything unique to the user in the authentication cookie? Should I serialize all of the user data and put that in the cookie and not use the session to store the user data?
My application is very simple and does not have any roles. I just want to make sure it would scale well if necessary.
For now, I just put the users email in the authentication cookie and add the user object to the session. I'm using the following code to authorize a user:
FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(
1,
user.Email,
DateTime.Now,
DateTime.Now.AddMinutes(15),
false,
user.Email); // adding the user email in the authTicket
string encTicket = FormsAuthentication.Encrypt(authTicket);
HttpCookie faCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket);
Session["User"] = user; //adding user data to session
Response.Cookies.Add(faCookie);
return RedirectToAction("Summary", "Account");
I really appreciate any insight. Thanks!