Session variables are getting overritten by different users in different locations

Hi, the session variables I'm using when the application starts, are getting overridden when a second user logs in

On my login page I'am initialising  a structure that contains some user data and I'm assigning that structure to a session variable.

myData md = new myData()
md.id = xx;
md.username = xxx;
Session["myData"] = md

Open in new window


Now, when second user logs in, this data gets overriden by the nbew user and the original user (logged in a different part of the country)  can see the second user data!

Any ideas how to stop this or why it's happening??
Adrian CrossAsked:
Who is Participating?
 
Obadiah ChristopherConnect With a Mentor Commented:
This seems highly unlikely. Are you using static when reading the Session variable?
0
 
Adrian CrossAuthor Commented:
It's a structure inside a class in another file

public class MyClass

public struct myData
{
     public string ID;
     public string username;
}

Open in new window


Then from login page aspx Im accessing it like

myData md = new myData();
md.id = 5;
Session["myData"] = md;

It's happening. Im just baffled
0
 
Obadiah ChristopherCommented:
Have you tried changing the structure to a class
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
Adrian CrossAuthor Commented:
Could you please give  me an example?
0
 
Obadiah ChristopherCommented:
I meant to say that instead of this

public struct myData
{
     public string ID;
     public string username;
}

Use this

public class myData
{
     public string ID;
     public string username;
}
0
 
Adrian CrossAuthor Commented:
You were right! I have declared a variable as static in another page which I didn't see!
Thanks so much!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.