"Session state can only be used when enableSessionState is set to true" Error

P

Paul

Hi All,

In my application, I wished to check certain things on each page
load, so rather than paste the same code in each pages constructor, I
thought it would be more logical to inherit from Page and place the
code in there. Then each webpage will inherit from my modified page
class. This works fine, but if I try and access the Session[] from the
modified page class, I get the following 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.

Any help in resolving this would be greatly appreciated!

Thanks.
 
G

Guest

Paul,
If you have this:

<pages enableSessionState="true" />

in your web.config, you should not be having an issue like this.
Peter
 
P

Paul

Paul,
If you have this:

<pages enableSessionState="true" />

in your web.config, you should not be having an issue like this.
Peter

Hi Peter,

Even with that in the web.config, the exact same error occurs.
I'm using the Session object in many places through the project, but
the only time it errors like in my first post is when I put it in a
class which inherits from PAGE.
 
P

Paul

Hi Peter,

Even with that in the web.config, the exact same error occurs.
I'm using the Session object in many places through the project, but
the only time it errors like in my first post is when I put it in a
class which inherits from PAGE.

Solved it. Because I was inheriting from Page class, the child
constructor was being called before the base constructor. This means
the Session object hadn't been created yet. I placed the needed code
in an overriden OnLoad event and it all works fine.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top