SessionHelper Class problem in ASP .NET

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ppuniversal
    New Member
    • Feb 2007
    • 52

    SessionHelper Class problem in ASP .NET

    Hi,
    I am facing the following problem while using my version of SessionHelper class in ASP.NET.

    The scenario is as follows:

    I have my version of SessionHelper Class where I store many of my session variables. One of them is UserID.

    Now there is a MyCommon.vb module file where I have a global instance of this SessionHelper class. Again, in the module file I have few methods which I call from my main program.

    Now the problem is that, if I declare a new instance of my session variable inside the methods of module file, then when I call say any method from my main program, then the value of my UserID returned from this local instance of SessionHelper classis, is the proper value of the required User.

    But if I do not declare a local copy and try to get the value of UserID from the global instance of SessionHelper class which was declare in the module, then sometimes I get garbage values of UserID i.e. I get certain UserIDs with which I had previously logged in.

    This question may not be very clear. If so, let me know, I will try to provide more details.

    Thanks
    Pawan.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Originally posted by ppuniversal
    Hi,
    I am facing the following problem while using my version of SessionHelper class in ASP.NET.

    The scenario is as follows:

    I have my version of SessionHelper Class where I store many of my session variables. One of them is UserID.

    Now there is a MyCommon.vb module file where I have a global instance of this SessionHelper class. Again, in the module file I have few methods which I call from my main program.

    Now the problem is that, if I declare a new instance of my session variable inside the methods of module file, then when I call say any method from my main program, then the value of my UserID returned from this local instance of SessionHelper classis, is the proper value of the required User.

    But if I do not declare a local copy and try to get the value of UserID from the global instance of SessionHelper class which was declare in the module, then sometimes I get garbage values of UserID i.e. I get certain UserIDs with which I had previously logged in.

    This question may not be very clear. If so, let me know, I will try to provide more details.

    Thanks
    Pawan.
    Hmm this is a problem with the way you are using your SessionHelper.

    If you declare a static global instance of your SessionHelper class, every person that uses your website will be accessing the Same data.

    Say one person visits your site, and after logging in their UserId is set to 1234.
    Then another person visits your site a couple seconds later...since you're using a global variable, their UserID will be 1234 as well..unless you set it to something else.

    Things can get pretty messed up if more than one person is using your SessionHelper instance at the same time.

    You should create a SessionHelper per user to avoid this, especially if each person requires a unique UserID to identify them.

    Does this make sense?

    Comment

    • ppuniversal
      New Member
      • Feb 2007
      • 52

      #3
      I would like to say that the global session variable is global only because its declared above all the methods in the Common.vb.....a nd not global at the application level.

      Do you mean to say that if I make a session variable global(like this), even in the Common.vb file (which only contains some common methods), the session variable becomes global to the whole application.

      Because in my case, I get proper value of session variable in almost every case. Its only that sometimes I get old session values.

      Thanks

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Originally posted by ppuniversal
        I would like to say that the global session variable is global only because its declared above all the methods in the Common.vb.....a nd not global at the application level.

        Do you mean to say that if I make a session variable global(like this), even in the Common.vb file (which only contains some common methods), the session variable becomes global to the whole application.
        I don't know why, but I read your question incorrectly.
        For some reason I thought you were using a static variable.

        Originally posted by ppuniversal
        Now the problem is that, if I declare a new instance of my session variable inside the methods of module file, then when I call say any method from my main program, then the value of my UserID returned from this local instance of SessionHelper classis, is the proper value of the required User.


        But if I do not declare a local copy and try to get the value of UserID from the global instance of SessionHelper class which was declare in the module, then sometimes I get garbage values of UserID i.e. I get certain UserIDs with which I had previously logged in.
        Could you please post your code for this. I'm having a hard time understanding your question.

        Comment

        Working...