The existance of session variables

T

Timothy V

Hi,
I was wondering how long the created session variables last for?

To be more clear, when are they destroyed? Do I have to set the variables to
null in Session_End()? Is the Session_End() method invoked when the browser
is closed?

I'm just not sure how it works.

Thanks in advance,

Tim.
 
G

Greg Burns

By default session variables expire 20 minutes since last page access. (You
can set this in web.config)

Session_End() is NOT invoked when the browser is closed.

Greg
 
G

Guest

Hi just started using session variables, no expert but this is what I have seen so far.
Session variables exist from when the web application is started until it is ended.
It is started when the browser of the user opens the start page and ends when the user no longer has any page open from the application. Session variables are visible to all pages of the application when invoked.
 
G

Greg Burns

If only that were true!

You need to be very careful. Say you have a session variable
session("username")="greg". If the users walks away from the machine and
comes back 20+ minutes later and causes a postback on your page a new
session will start.

When you go to access your session("username") variable that you thought was
populated you'll get an exception because it will be now equal to nothing!

This scenario has caused me many many headaches. ;(

You can/should always check your session variables for nothing before using
them. Same will Cache items, cause those can be purged at any point in time.

PS: If anybody has ever figured at a full proof way of displaying a session
expired page while using forms authentication, I would love to hear it!

Greg



Paul said:
Hi just started using session variables, no expert but this is what I have seen so far.
Session variables exist from when the web application is started until it is ended.
It is started when the browser of the user opens the start page and ends
when the user no longer has any page open from the application. Session
variables are visible to all pages of the application when invoked.
 

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

Members online

No members online now.

Forum statistics

Threads
474,434
Messages
2,571,685
Members
48,796
Latest member
Greg L.

Latest Threads

Top