session variable exists or not?
Its difficult to check whether a session name exists or not..
Because we cannot use a session instance name before it is being declared, means assigning the value to it. So it is better to use the following code. It is very bad programming. but if you want you can use it.
try
{
string data = Session["sessionIds"].tostring();
}
catch(Exception ex)
{
// Do your handling code. ie, if you want to set the session value set here.
}
the idea behind is that using the session variable before declaring the value will thow an error. By this we can make sure that the session variable is not existing.
If you want more specific just check what error throwing in this scenario and check whether the error is same as you required error and do the handling code.
make sure to check whether the error is not coming from any other reasons.
Usually the error will be "object reference not set to an instance of the object".
Hope this will help some one..