Object gets stored in session, but while retrieving it is null
On page load I am populating my own object, storing in session & it is getting stored, When I am debugging i can see that object is stored in session, But When I am reading that session variable.. it is null,
Surprizingly I am able to use other session variables,
Howerver I am able to get the session variable when my sessionstate = "InProc"... and I get it null when ses开发者_StackOverflowsionstate='StateServer' or sessionstate='SQLServer'
I've kept session TimeOut="20", On the page I've added EnableSessionState="True"
Please help, - Prashant C
Does your type implement ISerializable
(directly or indirectly, perhaps via inheritance)? The biggest difference between in-proc and the rest is that in-proc doesn't serialize, so serialization is the first thing to look at.
It does sound very odd, though - if it was "off", I would expect to get either an exception or an uninitialised object - not a null. Maybe a silly question, but the incoming request definitely has all the right headers/cookies? i.e. it still knows which session it is in?
To explain, if your type neither implements ISerializable
nor has [Serializable]
I would expect an exception; you've added [Serializable]
, but the fact that it didn't already error makes me think there is some ISerializable
in the mix.
sessionstate='StateServer' or sessionstate='SQLServer' requires that your Objects are serializable.
精彩评论