Quote:
HOW do you use session-per-request? In my understanding, this does not involve the HttpSession at all.
Correct. I have a Page base class. On Page Init, I create an ISession, which is accessible via a protected property. On Unload (or perhaps Dispose), I close the session.
Code:
public class Page : System.Web.UI.Page {
NHibernate.ISession nSession;
protected NHibernate.ISession NSession {
get {return this.nSession;}
}
override protected void OnInit(EventArgs e) {
this.nSession = this.OpenSession();
}
public override void Dispose() {
if (this.NSession != null) {
this.NSession.Close();
}
base.Dispose();
}
}
This pattern is not the problem though, the problem arises with serialized ISessions.
Quote:
The HttpContext object has a per-request lifecycle, so putting the ISession in there gives you session-per-request.
I initially used HttpContext as well, but I realized it wasn't really necessary since I only need access to the session from the Page itself. It's more straightforward this way, particularly for new developers.
Quote:
We store ISession (actually a wrapper around ISession) in the HttpSession; however, this only works when using InProc Session State. It will fail if using State Server or SQL Server. Which pretty much rules out web farms.
No, the ISession is fully serializable as long as your objects are marked Serializable. The only problem, as I described in the first post, is if the Application restarts while an ISession is serialized (due to an updated DLL for instance). When the ISession is deserialized, NHibernate attempts some sort of lookup which fails for some reason. This is the only thing keeping back session state servers and web farms. Anybody know what's going on?