title: No session bound to the current context
body: <p>I followed this tutorial: <a href="http://nhforge.org/blogs/nhibernate/archive/2011/03/03/effective-nhibernate-session-management-for-web-apps.aspx" rel="noreferrer">http://nhforge.org/blogs/nhibernate/archive/2011/03/03/effective-nhibernate-session-management-for-web-apps.aspx</a></p>
  
  <p>I am not getting a 'no session bound to the current context' error when trying to load a page (mvc 3).</p>
  
  <pre><code>public static ISessionFactory BuildSessionFactory()
          {
  
              return Fluently.Configure()
                  .Database(MsSqlConfiguration.MsSql2008 // 
                                .ConnectionString(@"Server=.\SQLExpress;Database=db1;Uid=dev;Pwd=123;")
                                .ShowSql())
                  //.ExposeConfiguration(c =&gt; c.SetProperty("current_session_context_class", "web"))
                  //.CurrentSessionContext&lt;CallSessionContext&gt;()             
                  .Mappings(m =&gt; m.FluentMappings
                                     .AddFromAssemblyOf&lt;User&gt;())
                  .ExposeConfiguration(cfg =&gt; new SchemaExport(cfg)
                                                  .Create(false, false))
                  .BuildSessionFactory();
          }
  </code></pre>
  
  <p>The actual error is in my Repository.cs file:</p>
  
  <p>Line 114:        public virtual T Get(int id)
  Line 115:        {
  Line 116:            return _sessionFactory.GetCurrentSession().Get(id);
  Line 117:        }
  Line 118:</p>
  
  <p>When I was debugging it, _sessionFactory wasn't null or anything, it just can't seem to find the bound session.</p>
  
  <p>I have the httpmodule wired up in my web.config, and it does get run so that's not the problem.</p>
  
  <p>In my nhibernate configuration, I tried both:</p>
  
  <pre><code>.ExposeConfiguration(c =&gt; c.SetProperty("current_session_context_class", "web"))
  </code></pre>
  
  <p>and</p>
  
  <pre><code>.CurrentSessionContext&lt;CallSessionContext&gt;()
  </code></pre>
  
  <p>But that didn't work.</p>