我在建立一個類來存儲會話中的用戶ID和用戶角色。我不確定當多個用戶同時在網站上時,這個班級的行爲如何。有沒有人看到這個問題?靜態會話類和多個用戶
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; }
}
}
無法測試並鼓勵使用靜態「全局」助手等不良做法。這不是一個技術問題,更多的是長期影響的心態問題 – MikeSW 2013-05-17 05:08:27