Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

session variables

Status
Not open for further replies.

samduncan

Programmer
Sep 14, 2000
6
GB
ok, please help.

if i create a session variable in page1.asp like this:

Session("myName")="Sam"

and try to read it from page2.asp like this:

Response.Write ("Name is = " &Session("myName"))

why is it blank?

I have spent all day, playing with arrays, collections etc, if I access the variable from within the same page, ie: page1.asp or the global.asa page its ok, I have also noticed the Sub Session_OnStart is called in the global.asa page every time I log into a page, regardless if I am currently in a session, this doesnt seam right, as i thought the Sub Session_OnStart was only called once per session?

Please help! I am only just beginning asp and really need to get my head around this so i can begin persisting and sharing data amoungst single user sessions and multiple users.

Thanks in anticipation!

Sam x


[sig][/sig]
 
Sam,
Assuming that cookies are enabled in the browser, and sessions are enabled on the server, you might be getting bit by a known IIS bug. In some cases, a new session gets started if you reference variables from more than one page. The suggested fix, as I remember, is to initialize the variable in the session_start event in global.asa. Search the knowledge base to get the definitive answer. [sig]<p>nick bulka<br><a href=mailto: > </a><br><a href= </a><br>Get your technical books at Bulka's Books<br>
[/sig]
 
umm, but the session_start is getting called every time i enter a new asp page, if i initialise the variables there, then they will be overwritten every time i go into a new asp page!
where can i find this knowledge base your are pointing me towards?

thanks for your help

Sam [sig][/sig]
 
Sam,
By initializing the session variables in session_onstart, you'll be overcoming the bug that causes the event to fire on every page. It will fire only once, like it's supposed to.
Sorry, I don't have a link to the knowledge base article. You can go to search.microsoft.com and try to find it, or just go into global.asa and initialize the variables and see what happens. You have nothing to lose, since the variables are getting re-initialized on every page anyway.
Sessions are enabled on the server, right? [sig]<p>nick bulka<br><a href=mailto: > </a><br><a href= </a><br>Get your technical books at Bulka's Books<br>
[/sig]
 
yer sessions are enabled on IIS , but I tryed a different IIS and it all worked fine.!!
god knows! [sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top