473,320 Members | 2,006 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

null Session object

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
2 4041
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jeremy Lew | last post by:
When my HttpHandler is processing a request when installed on a particular 2003 Server machine, the Context.Session object is null. Any idea why this might be? My handler implements...
5
by: simon | last post by:
I use session: If IsDBNull(Session("Source")) Then ' this is the line cause an error bindRptSell() End If But I get an error message: Object variable or With block variable not set....
4
by: Steve Richter | last post by:
this code compiles ok: public string AssureAnonUID( ) { if (Session == null) Session = Guid.NewGuid(); return Session.ToString(); } but this code does not: public string AssureAnonUID( )
3
by: Miguel | last post by:
Hi, I m new with aspnet. I am trying to do an application that writes the session in a cookie but the context.session is null. Here in the code, the cookieValue is allways without session, ......
5
by: Miguel | last post by:
ey, I m trying to make a new httpmodule but the session object is null. I m implementing IReadOnlySessionState but it keep on being null. I m novice in this enviroment, does anybody know what's...
3
by: JebBushell | last post by:
Here's my code: private void Page_Load(object sender, System.EventArgs e) { clientId = Session.ToString(); .... etc. It bombs on the assignment after the session has timed out...
14
by: R.A.M. | last post by:
Hello, I have created ASP.NET project in which I have a file Admin.cs. It contains static class Admin with some methods and properties. The problem is that in property get a reference...
2
by: preeti13 | last post by:
Hi guys i am here with my another probelm please help me.trying insert the value into the data base but getting the null value error .I am getting thsi error Cannot insert the value NULL into...
3
by: Madhur | last post by:
Hello I am delivering an asp.net 2.0 application to my customer. I need to know, If I need to check for the condition of HttpContext.Current to be null in my business logic. I have extensively...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.