Ich habe eine Klasse mit allen Sitzungsvariablen, die ich benutze. Können Sie mir bitte mitteilen, ob es Thread-sicher ist.Statische Klasse für den Zugriff auf Sitzung
public static class AppSession
{
private const string UserIdKey = "UserId";
public static int UserId
{
get { return GetSession<int>(UserIdKey); }
set { SetSession(UserIdKey, value); }
}
private static T GetSession<T>(string key)
{
var currentSession = HttpContext.Current.Session;
if (currentSession == null) return default(T);
if (currentSession[key] != null)
return (T) currentSession[key];
return default(T);
}
}
Beim Zugriff auf die Eigenschaft AppSession.UserId wird es threadsicher sein.