473,395 Members | 2,192 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,395 software developers and data experts.

How to test for HttpContext.Current.Session variable

I need to set a variable to a session variable (if that's what you call it)
like this:

dim ds as dataset = HttpContext.Current.Session("CustDataSet")

But I get an exception if this variable in the current session hasn't been
set yet so I need to test it. I tried:

If HttpContext.Current.Session("CustDataSet") = nothing then
HttpContext.Current.Session("CustDataSet") = GetCustDataSet()
End If

But I get an exception on this also and the exception message is:

"Object reference not set to an instance of an object."

How can I test for this?
--
mo*******@nospam.com
Nov 18 '05 #1
2 3308
I figured it out. It seems lately that no matter how much trouble shooting
I do I can't find the answer myself until I post it in the user group and
then Wa La! I figure it out.

If anyone cares.... I had the page property (EnableSessionState="False")
where it should be True. If its set to false, then none of the session
state stuff on the server is going to work. du...

--
mo*******@nospam.com
"moondaddy" <mo*******@nospam.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
I need to set a variable to a session variable (if that's what you call it) like this:

dim ds as dataset = HttpContext.Current.Session("CustDataSet")

But I get an exception if this variable in the current session hasn't been
set yet so I need to test it. I tried:

If HttpContext.Current.Session("CustDataSet") = nothing then
HttpContext.Current.Session("CustDataSet") = GetCustDataSet()
End If

But I get an exception on this also and the exception message is:

"Object reference not set to an instance of an object."

How can I test for this?
--
mo*******@nospam.com

Nov 18 '05 #2
Just so you know, it's most likely the Session object itself which is null.
The proper way to code this in C# would be

if (null != HttpContext.Current && null != HttpContext.Current.Session &&
null != HttpContext.Current.Session("CustDataSet")){
GetCustDataSet();
}
--
Thanks,

Eric Lawrence
Program Manager
Assistance and Worldwide Services

This posting is provided "AS IS" with no warranties, and confers no rights.

"moondaddy" <mo*******@nospam.com> wrote in message
news:#w*************@TK2MSFTNGP09.phx.gbl...
I need to set a variable to a session variable (if that's what you call it) like this:

dim ds as dataset = HttpContext.Current.Session("CustDataSet")

But I get an exception if this variable in the current session hasn't been
set yet so I need to test it. I tried:

If HttpContext.Current.Session("CustDataSet") = nothing then
HttpContext.Current.Session("CustDataSet") = GetCustDataSet()
End If

But I get an exception on this also and the exception message is:

"Object reference not set to an instance of an object."

How can I test for this?
--
mo*******@nospam.com

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Shawn | last post by:
In my application, I have users that are registered in SQL Server. When they login, a flag is set to indicate they are logged in (dll). The procedure to set that flag uses information stored in...
2
by: Francois Malgreve | last post by:
hello guys, I have some helper class in my ASP.NET pplication who basically contains static methods. I used them as helper methods to do small jobs that I can use at many places in my code. ...
4
by: Makarand Keer | last post by:
Hi All I have problem in using Threading. I have ASP.NET application in which I am using multithreading to start a process. Now the object instances which are used in this thread access...
15
by: Jason | last post by:
Currently, I am storing information about the currently logged on user in Session variables that are stored in SQL. However, I am using role-based security, so I am storing custom roles in a...
7
by: Keith Patrick | last post by:
After completely giving up on finding some way in my ASP.Net app to take a query string URL and redirect to it as a POST instead, I went with a system like so: Upon "redirection," all the...
0
by: Rodusa | last post by:
I am trying to replace cookies with the new "Asp.net 2.0 profiles" in my shopping cart application, but I am having trouble to access profile properties using HttpContext.Current.Profile. I can...
7
by: Hardy Wang | last post by:
Hi, I have a web application, code of ASPX page needs to call one static method in another class which does not inherit System.UI.Page class using System.Web; public class Utils { public...
2
by: Dave | last post by:
After some digging, I discovered HttpContext.Current.Session is null when trying to access a session variable, username, in my upload.cs code which is in the App_Code folder. I just determined...
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.