test session exist

  • Thread starter Thread starter Green
  • Start date Start date
G

Green

Hi,
I want to test whether a sesion exist, what can i do?
I use Session["name"].toString().length == 0 , but it will prompt the
error saying object is not referenced. How can i test Session["name"]
exist?

Thanks in advance!
 
Green said:
Hi,
I want to test whether a sesion exist, what can i do?
I use Session["name"].toString().length == 0 , but it will prompt
the error saying object is not referenced. How can i test
Session["name"] exist?

Thanks in advance!

Test it against null.
And as in your example, when it is null, it will complain with the given
error message.
 
First, check for the existance of the item in the session state collection
before accessing its properties:

if (Session["name"] == null)
{
// name does not exist in the Session state collection.
}
else
{
// Access Session["name"] here...
}

Hope I got the question correctly.

Hi,
I want to test whether a sesion exist, what can i do?
I use Session["name"].toString().length == 0 , but it will prompt the
error saying object is not referenced. How can i test Session["name"]
exist?

Thanks in advance!
 
And BTW, on the server side, the Session ALWAYS exists - unless it takes
longer than 20 minutes for the Page to process. Just want to make sure
there's no confusion between the Session Collection and its members.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living
 

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

Back
Top