Last post Aug 24, 2011 09:52 AM by Mike OBrien
Aug 22, 2011 07:59 PM|Outflank|LINK
I'm new so be gentle...
I am using an app with some global vars declared in my master page.
I am loggin in and setting a string (declared in masterpage) to username.
Problem is that when someone else on another computer logs in then the same string is set to the new user.
I have fixed this with the Session var BUT this has raised another question for me ... Question is : are variables declared on my master page (So I can use them on other pages) the same instance for other users as well thus two users could be changeing the
same var value?
Thanks in advance!
Aug 22, 2011 09:16 PM|Bryan Strader|LINK
Session variables are user specific, declaring variables in a page are specific to that instance of a page. So these are not shared to different users who are operating different sessions. If you want to use a variable globally you can put it in the global.asax
Aug 23, 2011 07:45 AM|Outflank|LINK
This is what I thought Bryan BUT my vars being declared in my MASTER page are definitely being altered from another session (Or at least appear to be?) Would declaring as Public static in the master page have anything to do with this? RE Session vars, is
there any way to declare a VAR scope as a session var OR is the std ASPX Session variable the only way?
Really appreciate your help!
Aug 23, 2011 11:49 PM|Bryan Strader|LINK
Being static could cause this behavior, can you just make them public? Remove the static modifier.
Aug 24, 2011 09:52 AM|Mike OBrien|LINK
I actually ran into the same problem recently. The site I'm creating is going to be used by a very specific group of people and very rarely will there be more than 20 people logged in at the same time, so I was able to create empty arrays of 1000 objects.
The instant someone logs in I go and grab the miliseconds from the server clock and create a session variable callled "pointer". Once I have the milliseconds I go through and create all the variables attached to a single user that I use in the app at the position
in each array using the "pointer" variable as the index. This eliminated the problem of having more than one user logged in at a time and allowed me to access user info on the server side without a problem.
But, I don't think it would work if you had a large amount of users logged in at the same time. Partially because as soon as you got over 500 users the chances of people logging in at the same millisecond is a lot more likely than if you are dealing with
20, and also because its not very memory efficient even setting the unused members of the arrays to nothing, unless you are really good at garbage collection I suppose.
*Edit: I just did a couple tests and it looks like the memory impact is a lot less than I thought. The memory usage on the server side and client side didn't change when I logged into three different instances of IE9 as 3 different users.
I'm sure theres a more elegant/widely used solution to this issue but this worked for me so I hope it at least helps.