I have always stored data for a user (after they logged in) in a Session variable, so I can use that data on any page.
I found out that another way to store information globally is to store it in a class, using { get; set;}
, and then calling that from any page.
Right now, I've used both these methods as a test, and they both work really 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 enough to store user data in a class like this, or should I stick with Session
objects?
Updated for Completeness Will this post do something like above, but for multiple users? How to access session variables from any class in ASP.NET?