I always saved data for the user (after logging in) in a session variable, so I can use this data on any page. I learned that another way to store information around the world is to store it in a class using { get; set;} { get; set;} , and then call it from any page.
Right now, I used both of these methods as a test, and they both work very well:
Session["LoginId"] = rdr["uniqueIdentifier"].ToString();
and
Member.LoginId = rdr["uniqueIdentifier"].ToString();
Where (In Member.cs )
public class Member { public static int Challenges { get; set; } public static int NicknameId { get; set; } public static string LoginId { get; set; } public static string FriendsListId { get; set; } public static void ClearVariables() { Challenges = 0; NicknameId = 0; LoginId = null; FriendsListId = null; } }
Global.asax
void Session_End(object sender, EventArgs e) { Member.ClearVariables(); }
My question is: is it safe to store user data in a class like this, or should I stick to Session objects?
Updated for completeness. Will this post do something like the above, but for multiple users? How to access session variables from any class in ASP.NET?
source share