title: How does "Require SSL" affect ASP.NET MVC application lifecycle?
body: <p>I have an application that taps into <code>BeginRequest</code> and <code>EndRequest</code> to set up and tear down NHibernate sessions like this:</p>
  
  <pre><code>BeginRequest += delegate
  {
      CurrentSessionContext.Bind(SessionFactory.OpenSession());
  };
  
  EndRequest += delegate
  {
      var session = CurrentSessionContext.Unbind(SessionFactory);
      session.Dispose();
  
      Container.Release(session);
  };
  </code></pre>
  
  <p>This works fine when deployed in IIS, until I check the "Require SSL" box. Once I do this, I get a <code>NullReferenceException</code> at <code>session.Dispose()</code>.</p>
  
  <p>I haven't debugged this yet and, yes, the fix is trivial, but I'm just curious about how "Require SSL" affects the lifecycle of a request. Is a session not set up on the server in these cases?</p>
  
  <p><strong>EDIT</strong>: Just to clarify, I'm referring to the "Require SSL" option in IIS configuration for the application, not the <code>RequireHttps</code> attribute for controllers.</p>