Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Sessions conflict when encapsulated in a static class static property?

I have an ASP.NET application that is accessed by 120-140 users at the same time on average. I use Session to get and set user specific info. To make things easy I've got a static a class called CurrentSession and it has a property called 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
}

And whenever I needed current user's info I just used to do:

CurrentSession.UserInfo;

Recently I've come across situations when wrong user info is retrieved. Is there a problem in my approach that can cause Session conflicts?

like image 487
Farid Imranov Avatar asked Nov 01 '22 12:11

Farid Imranov


1 Answers

No. It can't be that the session change can be caused by the static method. In fact, HttpContext.Current itself is a static. Assigning it to a static variable can cause this.

like image 178
Patrick Hofman Avatar answered Nov 13 '22 01:11

Patrick Hofman