By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,998 Members | 2,825 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,998 IT Pros & Developers. It's quick & easy.

null Session object

P: n/a
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
Nov 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"shland" wrote:
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);
}

--

Thanks,
Carl Prothman
Microsoft ASP.NET MVP

Nov 18 '05 #2

P: n/a
Hello shland,

Uh...

if (Session["mySessionVar"] != null)
{
... do something with Session["mySessionVar"]
}
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

--

--
Matt Berther
http://www.mattberther.com
Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.