Groups | Blog | Home
all groups > dotnet general > november 2005 >

dotnet general : test if session variable is set


eric
11/7/2005 2:57:07 PM
1 more thing ...
You may be able to grab the Session from the Request object.
eric
11/7/2005 3:02:47 PM
use "this." (intellisense) to see if the Session object is even
available in the location you're trying to use.
Jeff User
11/7/2005 9:08:04 PM
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 User
11/10/2005 9:54:49 PM
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

[quoted text, click to view]
AddThis Social Bookmark Button