All reference types (such as classes) are stored in memory as references.
Session State is memory. In other words, when you store an instance of a
class in Session State is not important. It will be stored in Session State
when you store it.
There are a couple of possibilities:
1. An exception occurs during the instantiation of the class, which results
in nothing being stored in Session. Have you checked to see whether it is
there immediately after you store it?
2. The application is restarting between the time you add the instance to
the Session and the time you re-read it from the Session. This can happen
when, for example, you are debugging and rebuilding your app when you start
the debugger.
3. Something is removing the instance from Session before you try to access
it.
4. Check your spelling. Is the key you use to insert it exactly the same as
the key you use to fetch it?
Other than that, without knowing anything else about your app, I can't
guess.
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer
Presuming that God is "only an idea" -
Ideas exist.
Therefore, God exists.
"Steven Blair" <st**********@btinternet.com> wrote in message
news:un****************@TK2MSFTNGP14.phx.gbl...
I have the following code:
Session["CurrentUser"] = new CurrentUser("TEST");
When I postback to the server, the Session["CurrentUser"] is null.
My guess is a only the refence to my actual class is stored, rather than
the class.
Looking on the internet, one solution posted was populating
Session["CurrentUser"] in
Session_Start in a global.asax file. Again, on postback, the value is
still null.
Can anyone help me out with this problem?
Steven
*** Sent via Developersdex http://www.developersdex.com ***