473,499 Members | 1,624 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

test if session variable is set

Hello
I am hoping someone knows the answers I seek..

I am writing code in a C# web service solution.
I want to create an instance of an object (that I created) in a
Session variable. I need to check to see if the Session variable has
been set yet. If the variable already contains an instance of this
object then I will retrieve and use the existing object, rather than
create a new instance. ie. I will only create a new object the first
time the procedure is called, and then save it for the next time.

So, in an article I found in my MSDN help entitled
"Code: Reading Values From Session State (Visual C#)"
the procedure recommended to check to see if the Session var was set
yet, is this:
if (Session["SomeVarName"] == null)

When I do this, I get the
"Object reference not set to an instance of an object" error.
Checking in debug, pointing to the word Session, the following
information pops up:
Session = <undefined value>

I thought Session was supposed to be created first thing when a page
is accessed. So, how come mine is not defined yet?

Could it be because it is an .asmx file rather than an aspx file?

If asmx pages don't create a Session object, is there a way to
maintain session information in a web service?

Thanks much
Jeff
Nov 7 '05 #1
3 1652
1 more thing ...
You may be able to grab the Session from the Request object.

Nov 7 '05 #2
use "this." (intellisense) to see if the Session object is even
available in the location you're trying to use.

Nov 7 '05 #3
Yes, that is the funny thing (to me anyway)
it shows up when typing this.
but yet, when trying to evaluate, it doesnt work.
I think that it is disables in a web service app, but am not sure how
to fix

Jeff

On 7 Nov 2005 15:02:47 -0800, "eric" <em****@cstone.net> wrote:
use "this." (intellisense) to see if the Session object is even
available in the location you're trying to use.


Nov 10 '05 #4

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

Similar topics

12
2465
by: George Hester | last post by:
I have always used this in ASP to test if the client is accepting cookies: <%@language="VBScript"%> <% Session ("nc") = 1 If Len(Session("nc")) = 0 Then 'Cookies Off Else 'Cookies On End If
2
3134
by: Jeff User | last post by:
Greetings I am writing code in a C# web service solution. I want to create an instance of an object (that I created) in a Session variable. I need to check to see if the Session variable has...
2
3313
by: moondaddy | last post by:
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...
1
1348
by: Aaron Fleming | last post by:
In classic ASP I have set a session variable, redirected to another page and requested the session variable. If it wasn't there ... redirect accordingly .. if so .. log in .. Is there a way to...
4
1939
by: T Ralya | last post by:
I am told that ASP.NET controls the session ID and session variables, but that does not fit my symptoms. I am posting here as directed. I'm hoping that someone can at least recommend something to...
4
1877
by: Jeff User | last post by:
Hello I am hoping someone knows the answers I seek.. I am writing code in a C# web service solution. I want to create an instance of an object (that I created) in a Session variable. I need to...
3
333
by: Jeff User | last post by:
Hello I am hoping someone knows the answers I seek.. I am writing code in a C# web service solution. I want to create an instance of an object (that I created) in a Session variable. I need to...
3
22894
by: Adam J Knight | last post by:
Hi all, I am trying to test to see if a Session variable exists. This was my initial attempt, and doesn't work int intInstructorID = (Session.ToString() == null ?...
3
1423
by: Alex | last post by:
Hello. Maybe someone can help me. My development computer has: WindowsXP SP2 and MSSQL Server 2000 and IIS 5.0(or 5.1) Our webserver has: Windows2003 SP1 and MSSQL Server 2005 and IIS 6.0 We are...
0
7012
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
7180
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,...
0
7225
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...
1
6901
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
7392
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...
0
5479
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3105
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...
1
667
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
307
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.