webpart context.session is null
- by tbischel
I've been using the session array to store a state variable for my webpart... so I have a property like this:
public INode RootNode
{
get
{
return this.Context.Session["RootNode"] as INode;
}
set
{
this.Context.Session["RootNode"] = value as object;
}
}
This usually works fine. I've discovered that sometimes, the context.session variable will be null.
I'd like to know what are the conditions that cause the session to be null in the first place, and whats the best way to persist my object when this happens? Can I just assign a new HttpSessionState object to the context, or does that screw things up?
Edit: Ok, so its not just the session that is null... the whole context is screwed up. When the webpart enters the init, the context is fine... but when it reaches the dropbox selectedindexchange postback event (the dropbox contains node id's to use to set the rootnode variable), the context contains mostly null properties.
also, it only seems to happen when certain id's are selected. This looks more like some kind of weird bug on my end than a problem with my understanding of the session.