Thursday, March 22, 2012

The existance of session variables

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.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
"Timothy V" <tripix@.msn.com> wrote in message
news:%23vc45NEcEHA.796@.TK2MSFTNGP09.phx.gbl...
> 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.
>
Hi just started using session variables, no expert but this is what I have s
een 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 whe
n the user no longer has any page open from the application. Session variab
les are visible to all pages of the application when invoked.
--
Paul G
Software engineer.
"Timothy V" wrote:

> 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 browse
r
> is closed?
> I'm just not sure how it works.
> Thanks in advance,
> Tim.
>
>
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" <Paul@.discussions.microsoft.com> wrote in message
news:182E0A10-B76F-4EFE-9B1F-A01ED839F4E3@.microsoft.com...
> 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.
> --
> Paul G
> Software engineer.
>
> "Timothy V" wrote:
>
variables to
browser
for further reading
http://support.microsoft.com/defaul...kb;en-us;555082
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
"Paul" <Paul@.discussions.microsoft.com> wrote in message
news:182E0A10-B76F-4EFE-9B1F-A01ED839F4E3@.microsoft.com...
> 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.
> --
> Paul G
> Software engineer.
>
> "Timothy V" wrote:
>
Sounds like a good idea to check if the session information is nothing as cu
rrently not doing that with my application so would cause problems--
Paul G
Software engineer.
"Greg Burns" wrote:

> 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 w
as
> 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 usin
g
> them. Same will Cache items, cause those can be purged at any point in tim
e.
> PS: If anybody has ever figured at a full proof way of displaying a sessio
n
> expired page while using forms authentication, I would love to hear it!
> Greg
>
> "Paul" <Paul@.discussions.microsoft.com> wrote in message
> news:182E0A10-B76F-4EFE-9B1F-A01ED839F4E3@.microsoft.com...
> seen so far.
> is ended.
> when the user no longer has any page open from the application. Session
> variables are visible to all pages of the application when invoked.
> variables to
> browser
>
>

0 comments:

Post a Comment