Session Variable

F

Flurry

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...
 
P

Patrice

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.
 
F

Flurry

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...
 
F

Flurry

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....
 
M

Mark Rae [MVP]

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...
 
J

Juan T. Llibre

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 español : http://asp.net.do/foros/
======================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top