Wednesday, March 23, 2011

Session Variable problems when storing an object in my Session

I have a log in page where I valid my users and based on this validation I store their user info in a session variable so I can access it at any time. To do this I am trying to store an instance of one of my dbml generated classes "UserInfo". So I populate the class and then store it in a session variable I call "user"

 UserInfo u = new UserInfo();
    u = dal.RetrieveUser(userID, userPass)
    Session["user"] = u;

The issue I am having with this is it seems to mix up these session variables between users. Or more specifically it always seems to take the information from the first user variable stored for each subsequent user that logs in. So user 1's info is being pulled in for User 2, User 3, etc...

Is my problem that my class "UserInfo" is somehow static? Or what is causing this to happen? My UserInfo class looks like this:

public partial class UserInfo
    {
        ...

EDIT: After further review it seems that my Session variables are in fact working properly but my custom menus are actually the problem.

From stackoverflow
  • Sounds more like an issue with the DAL than the session object. Can you verify that the userID passed each time is different and the RetrieveUser function is using the passed value and not a static one?

    Collin Estes : yeah I checked it and made sure but it is retrieving the right information and creating the session variable correctly. The userID is actually just the value of the text box from the login.
  • Are you testing this using the web client on the same computer or separate computers? For instance, by default FireFox will run in a single process even if you have multiple windows or tabs open. As silly as it sounds, a colleague of mine had not noticed this phenomena when he had the same issue.

0 comments:

Post a Comment