views:

1235

answers:

3

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 <configuration>\<system.web>\<httpModules> section in the application configuration."

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

<system.web>
...
    <sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes" cookieless="false" timeout="20"/>

    <globalization requestEncoding="utf-8" responseEncoding="utf-8"/>
    <httpHandlers>
        <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=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <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"/>
        <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"/>
    </httpHandlers>
    <xhtmlConformance mode="Legacy"/>
    <pages>
    <!-- enableSessionState="true" autoEventWireup="true" enableViewState="true" enableViewStateMac="true" -->
        <controls>
            <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
            <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        </controls>
    </pages>
    <httpModules>
        <!--<add name="Session" type="System.Web.SessionState.SessionStateModule"/>-->
        <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    </httpModules>
</system.web>

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?

Thanks, Jeff

+2  A: 

BREAKPOINTS!

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!

Ugh!

Jeff Keslinke
LOL...can't see the wood for the trees :) Glad you got it sorted.
Kev
A: 

Thanks Your answer saved lot of my hair which I was sure about to loose scratching my head with this problem for about a day. Removing the breakpoints did it.

Abbi
I'm glad that helped you out, internet is good for something ;)
Jeff Keslinke
A: 

Why do breakpoints cause the problem? Anyone know?

I had a breakpoint set on my base page constructor and was getting this exact issue. I removed the breakpoint and it works now.

Nathan