473,804 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4065
"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.Redire ct("~/Login.aspx", false);
}

--

Thanks,
Carl Prothman
Microsoft ASP.NET MVP

Nov 18 '05 #2
Hello shland,

Uh...

if (Session["mySessionV ar"] != null)
{
... do something with Session["mySessionV ar"]
}
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
5055
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 IRequiresSessionState and works normally on other machines. Thanks, Jeremy
5
1775
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. System.NullReferenceException: Object variable or With block variable not
4
1339
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
9589
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, ... I dont know how to get the session, maybe I cant... thanks in advance Miguel
5
7314
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 happening? thanks Miguel
3
2511
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 (System.NullReferenceException: Object reference not set to an instance of an object). I don't understand why it is processing the page load event at all.
14
29485
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 HttpContext.Current.Session is null, although for instance HttpContext.Current.Application or HttpContext.Current.Request is not null: public static class Admin {
2
2437
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 column 'EmployeeID', table 'Accomplishments.dbo.Accomplishment'; column does not allow nulls. INSERT fails. The statement has been terminated. and my code is this using System; using System.Collections;
3
8913
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 used Cache and Session objects, and currently I assume HttpContext.Current object to be existent. Also, since I do not have this check, some of my unit test cases fail because there is no HttpContext for them.
0
9712
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10595
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10343
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10341
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7634
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5530
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4308
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.