封装在静态类静态属性中时Sessions会发生冲突吗?

Far*_*nov 5 .net c# asp.net session

我有一个ASP.NET应用程序,平均可以同时由120-140个用户访问.我使用Session来获取和设置用户特定信息.为了方便起见,我有一个静态的类调用CurrentSession,它有一个名为UserInfo:

public static class CurrentSession{
     public static UserInfo{
          get{return HttpContext.Current.Session["userInfo"]!=null?(UserInfo)HttpContext.Current.Session["userInfo"]:null;}
          set{HttpContext.Current.Session["userInfo"]=value;}
     }
    //And other properties
}
Run Code Online (Sandbox Code Playgroud)

每当我需要当前用户的信息时,我就会这样做:

CurrentSession.UserInfo;
Run Code Online (Sandbox Code Playgroud)

最近我遇到了检索错误用户信息的情况.我的方法中是否存在可能导致Session冲突的问题?

Pat*_*man 2

不,会话变化不可能是由static方法引起的。事实上,HttpContext.Current它本身就是一个static。将其分配给静态变量可能会导致这种情况。