title: 'session state not available in this context' in IHttpModule AJAX Request
body: <p>I know this is a somewhat common issue but, I've yet to find a solution so, any and all help or comments really appreciated.</p>
  
  <p>In a IHttpModule implementation, in the Init method I've setup a handler as so:</p>
  
  <pre><code>public void Init(HttpApplication context)
  {
    context.PreRequestHandlerExecute += new EventHandler(PreRequestHandlerExecute);
  }
  </code></pre>
  
  <p>In the PreRequestHandlerExecute method, for any AJAX calls, I get a 'session state not available in this context' exception.</p>
  
  <pre><code>public void PostRequestHandlerExecute(Object application, EventArgs e)
      {
          HttpApplication app = application as HttpApplication;
          var a = app.Session["csrf_token"];
  </code></pre>
  
  <p>Alternatively, doing this results in an NullReferenceException</p>
  
  <pre><code>var b = HttpContext.Current.Session["csrf_token"];
  </code></pre>
  
  <p>I'm trying to access an object in the Session, the object is put there and read there during non-ajax calls without any issues.</p>
  
  <p>Question(s) specifically is:
  Is there an alternative location I can or should store the object in rather than the Session (other than a DB or Cookie)?</p>
  
  <p>--Or--</p>
  
  <p>Is there a way to make the Session available during an AJAX request, via some configuration or something maybe?</p>
  
  <p>--Or--</p>
  
  <p>Am I just doing something I shouldn't in .Net in general. I'm a native Java person, .Net concepts are new to me.</p>
  
  <p>(Trying to implement the 'Synchronizer Token Pattern' to prevent CSRF in an aspx MVP application  if that helps)</p>
  
  <p>Thanks Very Much
  John</p>