locked
Lifetime of data in static prperties of class RRS feed

  • Question

  • User-1552614833 posted

    I am using like this to get login user details , I want know is the any chance of data is sharing will done for each user sign in individually or data sharing will not be down .

    public class LoginUserUtility
            {
         public static string LoginUserId { get { return     HttpContext.Current.Session["UserId"].ToString(); } }
            public static string LoginUserName { get { return "admin"; } } //HttpContext.Current.Session["UserName"].ToString(); } }
            public static string LoginUserRoleId{ get { return HttpContext.Current.Session["RoleId"].ToString(); } }
            public static string LoginUserRoleName { get { return HttpContext.Current.Session["HotelId"].ToString(); } }
            public static string LoginUserCompanyId { get { return HttpContext.Current.Session["CompanyId"].ToString(); } }
      }

    Suggest any other better way to do this task ? I want access data without object creation of class .

    Does Static properties will change data based on login user session values .

    I am accessing values like LoginUserUtility.LoginUserName
    Tuesday, June 17, 2014 8:53 AM

Answers

  • User-417640953 posted

    Hi prk_in,

    Thanks for the post.

    Based on yoru code, we can get the current user's information using LoginUserUtility.LoginUserId or LoginUserUtility.LoginUserName.

    Does Static properties will change data based on login user session values .

    The static properties will change when currect user's session changed, that because it will return currect session when you access those properties.

    get { return  HttpContext.Current.Session["UserId"].ToString(); } }
    

    Hope that helps, thanks.

    Best Regards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 19, 2014 2:49 AM

All replies

  • User-1360095595 posted

    Does your code compile without errors? Why have you declared the properties static; what are you trying to accomplish? 

    Tuesday, June 17, 2014 9:02 AM
  • User-417640953 posted

    Hi prk_in,

    Thanks for the post.

    Based on yoru code, we can get the current user's information using LoginUserUtility.LoginUserId or LoginUserUtility.LoginUserName.

    Does Static properties will change data based on login user session values .

    The static properties will change when currect user's session changed, that because it will return currect session when you access those properties.

    get { return  HttpContext.Current.Session["UserId"].ToString(); } }
    

    Hope that helps, thanks.

    Best Regards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 19, 2014 2:49 AM