By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,606 Members | 2,016 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,606 IT Pros & Developers. It's quick & easy.

Wierd session state error

P: n/a
In my web.config I added <pages enableSessionState="true">.

In each of my pages I also added EnableSessionState="True" to the Page
declaration.

(I didn't think this was necessary, but...)

Any reason why even though I did this I keep getting this error....

Server Error in '/abc' Application.
--------------------------------------------------------------------------------

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>\<httpModulessection in the
application configuration.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Web.HttpException: 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>\<httpModulessection in the application
configuration.

Source Error:

Line 3: Inherits System.Web.UI.Page
Line 4:
Line 5: Dim c As abcshoppingcart = Session("Cart")
Line 6:
Line 7: Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

Source File: F:\work-related\websites\abc\Projects.aspx.vb Line: 5

Stack Trace:

[HttpException (0x80004005): 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>\<httpModulessection in the application
configuration.]
System.Web.UI.Page.get_Session() +2634804
Projects..ctor() in F:\work-related\websites\abc\Projects.aspx.vb:5
ASP.projects_aspx..ctor() in
F:\work-related\websites\abc\Projects.aspx.vb:912304
__ASP.FastObjectFactory_app_web_kwdoldj8.Create_AS P_projects_aspx() +47
System.Web.Compilation.BuildResultCompiledType.Cre ateInstance() +32
System.Web.Compilation.BuildManager.CreateInstance FromVirtualPath(VirtualPath
virtualPath, Type requiredBaseType, HttpContext context, Boolean
allowCrossApp, Boolean noAssert) +119
System.Web.UI.PageHandlerFactory.GetHandlerHelper( HttpContext context,
String requestType, VirtualPath virtualPath, String physicalPath) +33
System.Web.UI.PageHandlerFactory.System.Web.IHttpH andlerFactory2.GetHandler(HttpContext
context, String requestType, VirtualPath virtualPath, String physicalPath)
+40
System.Web.HttpApplication.MapHttpHandler(HttpCont ext context, String
requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig)
+160
System.Web.MapHandlerExecutionStep.System.Web.Http Application.IExecutionStep.Execute()
+93
System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean&
completedSynchronously) +155

--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.3053;
ASP.NET Version:2.0.50727.3053

Aug 18 '08 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Is this the extent of your session state tag?
<pages enableSessionState="true">

If so, that is your problem. You have to specify what type of state (most
likely inProc here) and potentially set a few other values as well. Here is
an example of using SQL Server:

<sessionState
mode="SQLServer"
sqlConnectionString="data source=db1;user
id=db1User;password=password"
cookieless="false"
timeout="20"
/>

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#

or just read it:
http://feeds.feedburner.com/GregoryBeamer

********************************************
| Think outside the box! |
********************************************
"Cirene" <ci****@nowhere.comwrote in message
news:uf*************@TK2MSFTNGP05.phx.gbl...
In my web.config I added <pages enableSessionState="true">.

In each of my pages I also added EnableSessionState="True" to the Page
declaration.

(I didn't think this was necessary, but...)

Any reason why even though I did this I keep getting this error....

Server Error in '/abc' Application.
--------------------------------------------------------------------------------

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>\<httpModulessection in
the application configuration.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Web.HttpException: 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>\<httpModulessection in the
application configuration.

Source Error:

Line 3: Inherits System.Web.UI.Page
Line 4:
Line 5: Dim c As abcshoppingcart = Session("Cart")
Line 6:
Line 7: Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

Source File: F:\work-related\websites\abc\Projects.aspx.vb Line: 5

Stack Trace:

[HttpException (0x80004005): 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>\<httpModulessection in the
application configuration.]
System.Web.UI.Page.get_Session() +2634804
Projects..ctor() in F:\work-related\websites\abc\Projects.aspx.vb:5
ASP.projects_aspx..ctor() in
F:\work-related\websites\abc\Projects.aspx.vb:912304
__ASP.FastObjectFactory_app_web_kwdoldj8.Create_AS P_projects_aspx() +47
System.Web.Compilation.BuildResultCompiledType.Cre ateInstance() +32

System.Web.Compilation.BuildManager.CreateInstance FromVirtualPath(VirtualPath
virtualPath, Type requiredBaseType, HttpContext context, Boolean
allowCrossApp, Boolean noAssert) +119
System.Web.UI.PageHandlerFactory.GetHandlerHelper( HttpContext context,
String requestType, VirtualPath virtualPath, String physicalPath) +33

System.Web.UI.PageHandlerFactory.System.Web.IHttpH andlerFactory2.GetHandler(HttpContext
context, String requestType, VirtualPath virtualPath, String physicalPath)
+40
System.Web.HttpApplication.MapHttpHandler(HttpCont ext context, String
requestType, VirtualPath path, String pathTranslated, Boolean
useAppConfig) +160

System.Web.MapHandlerExecutionStep.System.Web.Http Application.IExecutionStep.Execute()
+93
System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean&
completedSynchronously) +155

--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.3053;
ASP.NET Version:2.0.50727.3053


Aug 18 '08 #2

P: n/a
Instead of using a shoppingcart object in Session, have you tested with a
simple string value?

"Cirene" <ci****@nowhere.comwrote in message
news:uf*************@TK2MSFTNGP05.phx.gbl...
In my web.config I added <pages enableSessionState="true">.

In each of my pages I also added EnableSessionState="True" to the Page
declaration.

(I didn't think this was necessary, but...)

Any reason why even though I did this I keep getting this error....

Server Error in '/abc' Application.
--------------------------------------------------------------------------------

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>\<httpModulessection in
the application configuration.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Web.HttpException: 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>\<httpModulessection in the
application configuration.

Source Error:

Line 3: Inherits System.Web.UI.Page
Line 4:
Line 5: Dim c As abcshoppingcart = Session("Cart")
Line 6:
Line 7: Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

Source File: F:\work-related\websites\abc\Projects.aspx.vb Line: 5

Stack Trace:

[HttpException (0x80004005): 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>\<httpModulessection in the
application configuration.]
System.Web.UI.Page.get_Session() +2634804
Projects..ctor() in F:\work-related\websites\abc\Projects.aspx.vb:5
ASP.projects_aspx..ctor() in
F:\work-related\websites\abc\Projects.aspx.vb:912304
__ASP.FastObjectFactory_app_web_kwdoldj8.Create_AS P_projects_aspx() +47
System.Web.Compilation.BuildResultCompiledType.Cre ateInstance() +32

System.Web.Compilation.BuildManager.CreateInstance FromVirtualPath(VirtualPath
virtualPath, Type requiredBaseType, HttpContext context, Boolean
allowCrossApp, Boolean noAssert) +119
System.Web.UI.PageHandlerFactory.GetHandlerHelper( HttpContext context,
String requestType, VirtualPath virtualPath, String physicalPath) +33

System.Web.UI.PageHandlerFactory.System.Web.IHttpH andlerFactory2.GetHandler(HttpContext
context, String requestType, VirtualPath virtualPath, String physicalPath)
+40
System.Web.HttpApplication.MapHttpHandler(HttpCont ext context, String
requestType, VirtualPath path, String pathTranslated, Boolean
useAppConfig) +160

System.Web.MapHandlerExecutionStep.System.Web.Http Application.IExecutionStep.Execute()
+93
System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean&
completedSynchronously) +155

--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.3053;
ASP.NET Version:2.0.50727.3053



Aug 18 '08 #3

P: n/a
It works fine with a simple string. So the problem must be with storing the
object in Session. Any ideas why I can't do this?

the abcshoppingcart is basically defined as this...

Public Class abcshoppingcart
Public Customer as new abccustomer
Public Product as List(of abcproduct)
End Class

Any ideas? Thanks!

"Jeff Dillon" <je********@hotmailremove.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
Instead of using a shoppingcart object in Session, have you tested with a
simple string value?

"Cirene" <ci****@nowhere.comwrote in message
news:uf*************@TK2MSFTNGP05.phx.gbl...
>In my web.config I added <pages enableSessionState="true">.

In each of my pages I also added EnableSessionState="True" to the Page
declaration.

(I didn't think this was necessary, but...)

Any reason why even though I did this I keep getting this error....

Server Error in '/abc' Application.
--------------------------------------------------------------------------------

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>\<httpModulessection in
the application configuration.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Web.HttpException: 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>\<httpModulessection in the
application configuration.

Source Error:

Line 3: Inherits System.Web.UI.Page
Line 4:
Line 5: Dim c As abcshoppingcart = Session("Cart")
Line 6:
Line 7: Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

Source File: F:\work-related\websites\abc\Projects.aspx.vb Line: 5

Stack Trace:

[HttpException (0x80004005): 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>\<httpModulessection in the
application configuration.]
System.Web.UI.Page.get_Session() +2634804
Projects..ctor() in F:\work-related\websites\abc\Projects.aspx.vb:5
ASP.projects_aspx..ctor() in
F:\work-related\websites\abc\Projects.aspx.vb:912304
__ASP.FastObjectFactory_app_web_kwdoldj8.Create_AS P_projects_aspx() +47
System.Web.Compilation.BuildResultCompiledType.Cre ateInstance() +32

System.Web.Compilation.BuildManager.CreateInstanc eFromVirtualPath(VirtualPath
virtualPath, Type requiredBaseType, HttpContext context, Boolean
allowCrossApp, Boolean noAssert) +119
System.Web.UI.PageHandlerFactory.GetHandlerHelper( HttpContext context,
String requestType, VirtualPath virtualPath, String physicalPath) +33

System.Web.UI.PageHandlerFactory.System.Web.IHttp HandlerFactory2.GetHandler(HttpContext
context, String requestType, VirtualPath virtualPath, String
physicalPath) +40
System.Web.HttpApplication.MapHttpHandler(HttpCont ext context, String
requestType, VirtualPath path, String pathTranslated, Boolean
useAppConfig) +160

System.Web.MapHandlerExecutionStep.System.Web.Htt pApplication.IExecutionStep.Execute()
+93
System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean&
completedSynchronously) +155

--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.3053;
ASP.NET Version:2.0.50727.3053




Aug 19 '08 #4

P: n/a
"Cirene" <ci****@nowhere.comwrote in message
news:OW**************@TK2MSFTNGP06.phx.gbl...
It works fine with a simple string. So the problem must be with storing
the object in Session. Any ideas why I can't do this?

the abcshoppingcart is basically defined as this...

Public Class abcshoppingcart
Public Customer as new abccustomer
Public Product as List(of abcproduct)
End Class

Any ideas? Thanks!

"Jeff Dillon" <je********@hotmailremove.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>Instead of using a shoppingcart object in Session, have you tested with a
simple string value?

"Cirene" <ci****@nowhere.comwrote in message
news:uf*************@TK2MSFTNGP05.phx.gbl...
>>In my web.config I added <pages enableSessionState="true">.

In each of my pages I also added EnableSessionState="True" to the Page
declaration.

(I didn't think this was necessary, but...)

Any reason why even though I did this I keep getting this error....

Server Error in '/abc' Application.
--------------------------------------------------------------------------------

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.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Web.HttpException: 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>\<httpModulessection in
the application configuration.

Source Error:

Line 3: Inherits System.Web.UI.Page
Line 4:
Line 5: Dim c As abcshoppingcart = Session("Cart")
Line 6:
Line 7: Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

Source File: F:\work-related\websites\abc\Projects.aspx.vb Line: 5

Stack Trace:

[HttpException (0x80004005): 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>\<httpModulessection in
the application configuration.]
System.Web.UI.Page.get_Session() +2634804
Projects..ctor() in F:\work-related\websites\abc\Projects.aspx.vb:5
ASP.projects_aspx..ctor() in
F:\work-related\websites\abc\Projects.aspx.vb:912304
__ASP.FastObjectFactory_app_web_kwdoldj8.Create_AS P_projects_aspx()
+47
System.Web.Compilation.BuildResultCompiledType.Cre ateInstance() +32

System.Web.Compilation.BuildManager.CreateInstan ceFromVirtualPath(VirtualPath
virtualPath, Type requiredBaseType, HttpContext context, Boolean
allowCrossApp, Boolean noAssert) +119
System.Web.UI.PageHandlerFactory.GetHandlerHelper( HttpContext context,
String requestType, VirtualPath virtualPath, String physicalPath) +33

System.Web.UI.PageHandlerFactory.System.Web.IHtt pHandlerFactory2.GetHandler(HttpContext
context, String requestType, VirtualPath virtualPath, String
physicalPath) +40
System.Web.HttpApplication.MapHttpHandler(HttpCont ext context, String
requestType, VirtualPath path, String pathTranslated, Boolean
useAppConfig) +160

System.Web.MapHandlerExecutionStep.System.Web.Ht tpApplication.IExecutionStep.Execute()
+93
System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean&
completedSynchronously) +155

--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.3053;
ASP.NET Version:2.0.50727.3053





I think you problem is in this code (Line 5).

Line 3: Inherits System.Web.UI.Page
Line 4:
Line 5: Dim c As abcshoppingcart = Session("Cart")
Line 6:
Line 7: Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Question to you: When do you think Line 5 is executed. Answer "no clue" is
bad answer.

When you page (or any object) is created .NET runtime follows following
steps
1. Memory allocated for the object.
2. Memory is initialized according to the defaults or what you wrote (like
you did in line 5). so if you declared member variable Int it's initialized
with 0 unless you wrote Dim k as Int = 4
Then it's initialized with 4.
3. Constructor called.

Only after that object is 'declared' created and we or ASP.NET might start
working with it. IE assign member variables like Session, Page, Request,
Response...

The method PreInit called, then Init.....

so if you want to access Session object you must do it much later... Like in
Page_Load event for example.
George.
Aug 19 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.