Thursday, March 29, 2012

Session Variable

Hello...

I have a simple problem...when I create a session variable as such:

Session("ID") = 1

and read this varaible from time to time...

The problem is that it is shared by all users not just the user that
created the session variable...

That is, if another user logs on and sets

Session("ID") = 2

then this will change the value if Session("ID") for the first
user...

What I want is to have different ID's for each user...

Can someone elxplain what is wrong?

Thanks...It shouldn't happen and I've never seent that. Are you sure this is
System.Web.HttpContext.Current.Session and not some other cusom session
object. You can also dump the SessionID to see if this is the same value (is
this hardcoded somewhere ?). What if you do a bare bone sample that shoes
that in your dev server on a bare bone site. Do you have the same problem ?

Ah ! Do you open another window and test to check this ? Note that when you
open another window (without relancunhing i..e) the new window uses the same
session.

--
Patrice

"Flurry" <cj406168@.stmail.staffs.ac.uka crit dans le message de news:
1189422564.511977.244720@.d55g2000hsg.googlegroups. com...

Quote:

Originally Posted by

Hello...
>
I have a simple problem...when I create a session variable as such:
>
Session("ID") = 1
>
and read this varaible from time to time...
>
The problem is that it is shared by all users not just the user that
created the session variable...
>
That is, if another user logs on and sets
>
Session("ID") = 2
>
then this will change the value if Session("ID") for the first
user...
>
What I want is to have different ID's for each user...
>
Can someone elxplain what is wrong?
>
Thanks...
>


You must be doing something else in your code that you haven't shown, or you
are using another Browser window from the same session, because this is
definitely *not* the expected behavior.
-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com
"Flurry" wrote:

Quote:

Originally Posted by

Hello...
>
I have a simple problem...when I create a session variable as such:
>
Session("ID") = 1
>
and read this varaible from time to time...
>
The problem is that it is shared by all users not just the user that
created the session variable...
>
That is, if another user logs on and sets
>
Session("ID") = 2
>
then this will change the value if Session("ID") for the first
user...
>
What I want is to have different ID's for each user...
>
Can someone elxplain what is wrong?
>
Thanks...
>
>


Hello and thank you both for your reply...

This is strange...the code is very simple...I have two aspx pages:-

Page 1 has the following code

System.Web.HttpContext.Current.Session ("Country" ) = countryCode
server.transfer("FOTrans.aspx")

FOTrans.aspx just reads the country code as follows...

countryCode = System.Web.HttpContext.Current.Session("country")

However, as I said before the session variable is shared between
users. I have just tried logging on using two different PC's and the
problem exists. If I set Session("Country") to USA on the first pc
then set it to UK in the second pc, the first pc reads UK not USA...

Any ideas as to what could be wrong?

Thanks...
re:
!System.Web.HttpContext.Current.Session ("Country" ) = countryCode

Where dos the value for countryCode come from ?

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espaol : http://asp.net.do/foros/
======================================
"Flurry" <cj406168@.stmail.staffs.ac.ukwrote in message news:1189430823.328225.66540@.57g2000hsv.googlegrou ps.com...

Quote:

Originally Posted by

Hello and thank you both for your reply...
>
This is strange...the code is very simple...I have two aspx pages:-
>
Page 1 has the following code
>
System.Web.HttpContext.Current.Session ("Country" ) = countryCode
server.transfer("FOTrans.aspx")
>
FOTrans.aspx just reads the country code as follows...
>
countryCode = System.Web.HttpContext.Current.Session("country")
>
However, as I said before the session variable is shared between
users. I have just tried logging on using two different PC's and the
problem exists. If I set Session("Country") to USA on the first pc
then set it to UK in the second pc, the first pc reads UK not USA...
>
Any ideas as to what could be wrong?
>
Thanks...
>
>
>


Thanks for your replies...however, I've discovered my mistake...I'm
using a shared variable to hold the Session("Country") e.g.

Shared countryCode as String.
CountryCode = Session("Country")

I was using the shred variable as a global variable...I just didn't
realise that shared variables have scope outside their own session.
This is right isn't it?

Thanks for your help...
"Flurry" <cj406168@.stmail.staffs.ac.ukwrote in message
news:1189433300.687467.258850@.50g2000hsm.googlegro ups.com...

Quote:

Originally Posted by

Thanks for your replies...however, I've discovered my mistake...I'm
using a shared variable to hold the Session("Country") e.g.
>
Shared countryCode as String.
CountryCode = Session("Country")
>
I was using the shared variable as a global variable...I just didn't
realise that shared variables have scope outside their own session.
This is right isn't it?


Yes it is. Shared variables in ASP.NET need *extremely* careful
management...

Avoid them if you can...

--
Mark Rae
ASP.NET MVP
http://www.markrae.net
re:
!shared variables have scope outside their own session.
!This is right isn't it?

Exactly, and that is why I asked where that value came from.
I suspected you were setting a global variable.

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espaol : http://asp.net.do/foros/
======================================
"Flurry" <cj406168@.stmail.staffs.ac.ukwrote in message news:1189433300.687467.258850@.50g2000hsm.googlegro ups.com...

Quote:

Originally Posted by

Thanks for your replies...however, I've discovered my mistake...I'm
using a shared variable to hold the Session("Country") e.g.
>
Shared countryCode as String.
CountryCode = Session("Country")
>
I was using the shred variable as a global variable...I just didn't
realise that shared variables have scope outside their own session.
This is right isn't it?
>
Thanks for your help...
>
>

0 comments:

Post a Comment