Sto costruendo una classe per memorizzare l'ID utente e il ruolo utente in una sessione. Non sono sicuro di come si comporterà questa classe quando più utenti si trovano sul sito nello stesso momento. Qualcuno vede un problema con questo?Classe di sessioni statiche e più utenti
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; }
}
}
Untestable e incoraggia le cattive pratiche come l'utilizzo di helper "globali" statici. Non è un problema tecnico, più un problema mentale con effetti a lungo termine – MikeSW