You can put whatever you want into the auth cookie if you find this useful. However, if you post sensitive information, you should at least encrypt it, but I would recommend that you do not post sensitive information there. You can do something like:
Forms.SetAuthCookie (UserName + "|" + UserId, true);
Then, when you need a username or user ID, it is. Just upload a cookie and analyze the values ββyou need.
Again, I would advise you not to do this, especially since it is presented above . However, it is possible. You must create access methods to pull the data:
public int CurrentUserId { get { int userId = 0; if (HttpContext.Current.Request.IsAuthenticated) { userId = Convert.ToInt32(HttpContext.Current.User.Identity.Name.Split('|')[1]); } return userId; } } public string CurrentUserName { get { string userName = string.Empty; if (HttpContext.Current.Request.IsAuthenticated) { userName = HttpContext.Current.User.Identity.Name.Split('|')[0]; } return userName; } }
andymeadows Jul 19 '09 at 15:06 2009-07-19 15:06
source share