0
私は使用するすべてのセッション変数を持つクラスを持っています。スレッドセーフであるかどうか教えてください。セッションにアクセスするための静的クラス
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);
}
}
プロパティAppSession.UserIdにアクセスすると、スレッドセーフになります。