468,780 Members | 2,254 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,780 developers. It's quick & easy.

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

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.

Feb 11 '07 #1
3 34053
Paul,
If you have this:

<pages enableSessionState="true" />

in your web.config, you should not be having an issue like this.
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"Paul" wrote:
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.

Feb 11 '07 #2
On 11 Feb, 15:45, Peter Bromberg [C# MVP]
<pbromb...@yahoo.yabbadabbadoo.comwrote:
Paul,
If you have this:

<pages enableSessionState="true" />

in your web.config, you should not be having an issue like this.
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net
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.
Feb 11 '07 #3
On 11 Feb, 17:22, "Paul" <Gef.Mongo...@gmail.comwrote:
On 11 Feb, 15:45, Peter Bromberg [C# MVP]

<pbromb...@yahoo.yabbadabbadoo.comwrote:
Paul,
If you have this:
<pages enableSessionState="true" />
in your web.config, you should not be having an issue like this.
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net

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.

Feb 11 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by bajopalabra | last post: by
1 post views Thread by Bill Cohagan | last post: by
1 post views Thread by =?Utf-8?B?QUcgTW9yZW5v?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.