null Session object

  • Thread starter Thread starter shland
  • Start date Start date
S

shland

Hi - I have a page in which I'm using session variables... The first time
someone goes to the page, obviously the session objects are null. But the
user can return to the page, at which time the session objects won't be
null.

On initializing the page, what's the syntax to check to see if the session
object is null before trying to access it? I did search the msdn help, but
I'm not finding exactly what I need here. - Using C#.

Thanks,
Sheryl
 
shland said:
On initializing the page, what's the syntax to check to see if the session
object is null before trying to access it? I did search the msdn help, but
I'm not finding exactly what I need here. - Using C#.

Sheryl,
I use the following C# code to check if a variable is in Session or not.

// If the session has timed out or the user has not logged in
if (Session["IsLoggedIn"]==null || (bool)Session["IsLoggedIn"]==false)
{
// Redirect to the login page
Response.Redirect("~/Login.aspx", false);
}
 
Hello shland,

Uh...

if (Session["mySessionVar"] != null)
{
... do something with Session["mySessionVar"]
}
 
Back
Top