Session timeout in ASP.NET 2.0

  • Thread starter Thread starter tirathankarg
  • Start date Start date
T

tirathankarg

hi,
I am storing some values in Session object. I am accessing these values
as Session["var"]. However there are times when i get error "Object
reference not set". This is because session has timed out and i try to
access some value stored in this object. How can I avoid this? Isnt
there any way in ASP.NEt 2.0 where before accessing any value, i check
if session exists or not? soemthing like "Session.IsExists". OR what
are the other ways of solving this problem.

Thanks
Tirath
 
I am storing some values in Session object. I am accessing these values
as Session["var"]. However there are times when i get error "Object
reference not set". This is because session has timed out and i try to
access some value stored in this object. How can I avoid this? Isnt
there any way in ASP.NEt 2.0 where before accessing any value, i check
if session exists or not? soemthing like "Session.IsExists". OR what
are the other ways of solving this problem.

if (Session.IsNewSession)
{
// do something...
}
 
In addition to what Mark said, you can also check if Session["var"] == null,
to see if there is anything actually in the session variable.
 
Oh.. just a poor statement i made :)
I 'prefer' not to use sessionvars except for passing a var from one page to
another, iow i don't remain depending on the var for longer period of time.

okidoki?
 
Back
Top