Session timeout in ASP.NET 2.0

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
 
M

Mark Rae

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

Marina Levit [MVP]

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

Edwin Knoppert

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?
 

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
473,770
Messages
2,569,584
Members
45,076
Latest member
OrderKetoBeez

Latest Threads

Top