Wierd session state error

  • Thread starter Thread starter Cirene
  • Start date Start date
C

Cirene

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>\<httpModules> section 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>\<httpModules> section 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_ASP_projects_aspx() +47
System.Web.Compilation.BuildResultCompiledType.CreateInstance() +32
System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(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.IHttpHandlerFactory2.GetHandler(HttpContext
context, String requestType, VirtualPath virtualPath, String physicalPath)
+40
System.Web.HttpApplication.MapHttpHandler(HttpContext context, String
requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig)
+160
System.Web.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
+93
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&
completedSynchronously) +155
 
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 said:
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>\<httpModules> section 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>\<httpModules> section 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_ASP_projects_aspx() +47
System.Web.Compilation.BuildResultCompiledType.CreateInstance() +32

System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(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.IHttpHandlerFactory2.GetHandler(HttpContext
context, String requestType, VirtualPath virtualPath, String physicalPath)
+40
System.Web.HttpApplication.MapHttpHandler(HttpContext context, String
requestType, VirtualPath path, String pathTranslated, Boolean
useAppConfig) +160

System.Web.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
+93
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&
completedSynchronously) +155
 
Instead of using a shoppingcart object in Session, have you tested with a
simple string value?

Cirene said:
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>\<httpModules> section 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>\<httpModules> section 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_ASP_projects_aspx() +47
System.Web.Compilation.BuildResultCompiledType.CreateInstance() +32

System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(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.IHttpHandlerFactory2.GetHandler(HttpContext
context, String requestType, VirtualPath virtualPath, String physicalPath)
+40
System.Web.HttpApplication.MapHttpHandler(HttpContext context, String
requestType, VirtualPath path, String pathTranslated, Boolean
useAppConfig) +160

System.Web.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
+93
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&
completedSynchronously) +155
 
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 said:
Instead of using a shoppingcart object in Session, have you tested with a
simple string value?

Cirene said:
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>\<httpModules> section 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>\<httpModules> section 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_ASP_projects_aspx() +47
System.Web.Compilation.BuildResultCompiledType.CreateInstance() +32

System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(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.IHttpHandlerFactory2.GetHandler(HttpContext
context, String requestType, VirtualPath virtualPath, String
physicalPath) +40
System.Web.HttpApplication.MapHttpHandler(HttpContext context, String
requestType, VirtualPath path, String pathTranslated, Boolean
useAppConfig) +160

System.Web.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
+93
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&
completedSynchronously) +155
 
Cirene said:
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 said:
Instead of using a shoppingcart object in Session, have you tested with a
simple string value?

Cirene said:
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>\<httpModules> section 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>\<httpModules> section 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_ASP_projects_aspx()
+47
System.Web.Compilation.BuildResultCompiledType.CreateInstance() +32

System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(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.IHttpHandlerFactory2.GetHandler(HttpContext
context, String requestType, VirtualPath virtualPath, String
physicalPath) +40
System.Web.HttpApplication.MapHttpHandler(HttpContext context, String
requestType, VirtualPath path, String pathTranslated, Boolean
useAppConfig) +160

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


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.
 
Back
Top