title: .NET Session not working
body: <p>This is a weird one, but hopefully someone can give me an idea here. I'm putting a few values into session in the <code>Session_Start</code> of the <code>Global.asax</code> in my app. Immediately after the <code>Session_Start</code> my base page's <code>OnInit</code> gets called and tries to use one of those <code>Session</code> variables.</p>
  
  <p>The weird part is sometimes it works, and then after NO changes will start giving me this error:</p>
  
  <blockquote>
    <p>"Session state can only be used when
    <code>enableSessionState</code> is set to <code>true</code>,
    either in a configuration file or in
    the <code>Page</code> directive. Please also make
    sure that
    <code>System.Web.SessionStateModule</code> or a
    custom session state module is
    included in the
    <code>&lt;configuration&gt;\&lt;system.web&gt;\&lt;httpModules&gt;</code>
    section in the application
    configuration."</p>
  </blockquote>
  
  <p>I've looked and looked finding all different ways on enabling session in the <code>web.config</code>. Here is what it looks like now:</p>
  
  <pre><code>&lt;system.web&gt;
  ...
      &lt;sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes" cookieless="false" timeout="20"/&gt;
  
      &lt;globalization requestEncoding="utf-8" responseEncoding="utf-8"/&gt;
      &lt;httpHandlers&gt;
          &lt;add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax"/&gt;
          &lt;remove verb="*" path="*.asmx"/&gt;
          &lt;add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/&gt;
          &lt;add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/&gt;
          &lt;add verb="GET,HEAD" path="ScriptResource.axd" validate="false" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/&gt;
      &lt;/httpHandlers&gt;
      &lt;xhtmlConformance mode="Legacy"/&gt;
      &lt;pages&gt;
      &lt;!-- enableSessionState="true" autoEventWireup="true" enableViewState="true" enableViewStateMac="true" --&gt;
          &lt;controls&gt;
              &lt;add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/&gt;
              &lt;add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/&gt;
          &lt;/controls&gt;
      &lt;/pages&gt;
      &lt;httpModules&gt;
          &lt;!--&lt;add name="Session" type="System.Web.SessionState.SessionStateModule"/&gt;--&gt;
          &lt;add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/&gt;
      &lt;/httpModules&gt;
  &lt;/system.web&gt;
  </code></pre>
  
  <p>You can see I have some stuff commented out, specifically the <code>enableSessionState="true"</code> and <code>&lt;add name="Session" type="System.Web.SessionState.SessionStateModule"/&gt;</code> because they were never there before and it always used to work. But I've tried it with them both enabled, one or the other enabled, it just doesn't make a difference.</p>
  
  <p>This is an app that has been in production for years, I'm only making minor changes, probably the biggest of which is adding a "titlebar" page to it, and upgrading from 2.0 to 3.5. I haven't tried adding the <code>enableSessionState</code> to the page directives because it didn't work in the <code>web.config</code> I don't see why it would work directly on the page, and I'd hate to dirty the app up anymore or waste anymore time trying in vain to enable session.</p>
  
  <p>Anyone have any other ideas?</p>
  
  <p>Thanks,
  Jeff</p>