all groups > asp.net > april 2004 >
You're in the

asp.net

group:

null Session object


null Session object shland
4/30/2004 8:13:57 PM
asp.net:
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

RE: null Session object Carl Prothman [ASP.NET MVP]
4/30/2004 8:52:01 PM
[quoted text, click to view]

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);
}

--

Thanks,
Carl Prothman
Microsoft ASP.NET MVP
Re: null Session object Matt Berther
4/30/2004 11:01:43 PM
Hello shland,

Uh...

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

[quoted text, click to view]
--

--
Matt Berther
AddThis Social Bookmark Button