.NET Session not working


This is a weird one, but hopefully someone can give me an idea here. I'm putting a few values into session in the Session_Start of the Global.asax in my app. Immediately after the Session_Start my base page's OnInit gets called and tries to use one of those Session variables.

The weird part is sometimes it works, and then after NO changes will start giving me this error:

"Session state can only be used when
enableSessionState is set to true,
either in a configuration file or in
the Page directive. Please also make
sure that
System.Web.SessionStateModule or a
custom session state module is
included in the
section in the application

I've looked and looked finding all different ways on enabling session in the web.config. Here is what it looks like now:

    <sessionState mode="InProc" stateConnectionString="tcpip=" sqlConnectionString="data source=;Trusted_Connection=yes" cookieless="false" timeout="20"/>

    <globalization requestEncoding="utf-8" responseEncoding="utf-8"/>
        <add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax"/>
        <remove verb="*" path="*.asmx"/>
        <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add verb="GET,HEAD" path="ScriptResource.axd" validate="false" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    <xhtmlConformance mode="Legacy"/>
    <!-- enableSessionState="true" autoEventWireup="true" enableViewState="true" enableViewStateMac="true" -->
            <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
            <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <!--<add name="Session" type="System.Web.SessionState.SessionStateModule"/>-->
        <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

You can see I have some stuff commented out, specifically the enableSessionState="true" and <add name="Session" type="System.Web.SessionState.SessionStateModule"/> 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.

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 enableSessionState to the page directives because it didn't work in the web.config 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.

Anyone have any other ideas?


Best Solution


I had breakpoints set in the constructor methods of the base page, and the main page, as well as the Session_Start and the OnInit. A coworker deleted all breakpoints in the debugger and the problem dissappeared!


Related Question