test if session variable is set

J

Jeff User

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
 
E

eric

use "this." (intellisense) to see if the Session object is even
available in the location you're trying to use.
 
J

Jeff User

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top