Estoy creando una clase para almacenar ID de usuario y función de usuario en una sesión. No estoy seguro de cómo se comportará esta clase cuando haya varios usuarios en el sitio al mismo tiempo. ¿Alguien ve un problema con esto?Clase de sesión estática y usuarios múltiples
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 y fomenta malas prácticas como el uso de ayudantes "globales" estáticos. No es un problema técnico, más un problema de mentalidad con efectos a largo plazo – MikeSW