As David M said, you need to make sure you bind your NHibernate session. Here's how I do it right now in my ASP.NET application:
public class NHHttpModule : IHttpModule { public void Init(HttpApplication context) { context.EndRequest += ApplicationEndRequest; context.BeginRequest += ApplicationBeginRequest; } public void ApplicationBeginRequest(object sender, EventArgs e) { CurrentSessionContext.Bind(NHSessionFactory.GetNewSession()); } public void ApplicationEndRequest(object sender, EventArgs e) { ISession currentSession = CurrentSessionContext.Unbind( NHSessionFactory.GetSessionFactory()); currentSession.Close(); currentSession.Dispose(); } public void Dispose() {
I create a custom HttpModule that binds my session for each request, and then add this module to my web.config as follows:
<httpModules> <add name="NHHttpModule" type="MyApplication.Core.NHHttpModule, MyApplication, Version=1.0.0.0, Culture=neutral" /> </httpModules>
I'm sure your configuration is different from this, but this is just an example of how I bind a session. Hope this helps a bit.
Calebhc
source share