Buduję klasę do przechowywania ID użytkownika i roli użytkownika w sesji. Nie jestem pewien, jak ta klasa będzie się zachowywać, gdy w witrynie jednocześnie jest wielu użytkowników. Czy ktoś widzi z tym problem?Statyczna klasa sesji i wielu użytkowników
public static class SessionHandler
{
//*** Session String Values ***********************
private static string _userID = "UserID";
private static string _userRole = "UserRole";
//*** Sets and Gets **********************************************************
public static string UserID
{
get
{
if (HttpContext.Current.Session[SessionHandler._userID] == null)
{ return string.Empty; }
else
{ return HttpContext.Current.Session[SessionHandler._userID].ToString(); }
}
set
{ HttpContext.Current.Session[SessionHandler._userID] = value; }
}
public static string UserRole
{
get
{
if (HttpContext.Current.Session[SessionHandler._userRole] == null)
{ return string.Empty; }
else
{ return HttpContext.Current.Session[SessionHandler._userRole].ToString(); }
}
set
{ HttpContext.Current.Session[SessionHandler._userRole] = value; }
}
}
Niewłaściwe i zachęca do złych praktyk, takich jak używanie statycznych "globalnych" pomocników. Nie jest to problem techniczny, bardziej problem z mentalnością o długoterminowych skutkach. – MikeSW