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

How to use Session ?

P: n/a
I am using Visual Studio 2005. In my ASPX page, when I try to use Session, I
got the 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>\<httpModulessection in the
application configuration."
In my Web.config I put the following, but still I got the error above:

<system.web>
<pages autoEventWireup="true" enableSessionState="true"
enableViewState="true" enableViewStateMac="true" smartNavigation="true"
validateRequest="false">
<controls>
<add tagPrefix="asp" namespace="System.Web.UI"
assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35"/>
</controls>
</pages>
<compilation debug="true">
:
</compilation>
<httpHandlers>
:
</httpHandlers>
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35"/>
<add name="Session" type="System.Web.SessionState.SessionStateModule"/>
</httpModules>
<!-- Enable in-process session state for application -->
<sessionState mode="InProc" cookieless="false" timeout="20"/>
</system.web>

How can I use the Session ? Thank you.
May 31 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
re:
!How can I use the Session ?

Why don't you try a simple web.config, like :

------------------------------------------------------------
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<pages enableSessionState = "true" />
<compilation debug="true" />
<sessionState mode="InProc" cookieless="false" timeout="20" />
</system.web>
</configuration>
----------------------------------------------------------

Check to see if it works, and then add other configuration
attributes until you find the one which is interfering ?

To check whether it's working or not, in any page, in Page_Load, set a session variable :

---------------------------------------------
<%@ Page Language="VB" %>
<script language="VB" runat="server">
Sub Page_Load(Sender As Object, E As EventArgs)
Session("somevar") = "somevalue"
SessionState.Text = Session("somevar")
End Sub
</script>
<html>
<head>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label id="SessionState" runat="server"/></asp:Label<br />
</div>
</form>
</body>
</html>
-----------------

....and retrieve the value in a Label in the same page.

In this example, if Session is working, you'll see the text "somevalue" returned.


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"fniles" <fn****@pfmail.comwrote in message news:Oc**************@TK2MSFTNGP05.phx.gbl...
>I am using Visual Studio 2005. In my ASPX page, when I try to use Session, I got the 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>\<httpModulessection
in the application configuration."
In my Web.config I put the following, but still I got the error above:

<system.web>
<pages autoEventWireup="true" enableSessionState="true" enableViewState="true"
enableViewStateMac="true" smartNavigation="true" validateRequest="false">
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions,
Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</controls>
</pages>
<compilation debug="true">
:
</compilation>
<httpHandlers>
:
</httpHandlers>
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions,
Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add name="Session" type="System.Web.SessionState.SessionStateModule"/>
</httpModules>
<!-- Enable in-process session state for application -->
<sessionState mode="InProc" cookieless="false" timeout="20"/>
</system.web>

How can I use the Session ? Thank you.

May 31 '07 #2

P: n/a
Thank you.
I needed the other stuffs in the web.config because I am using AJAX.
I fixed the problem by making the <pagessimpler like the following:

<system.web>
<pages enableSessionState="true">
<controls>
<add tagPrefix="asp" namespace="System.Web.UI"
assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35"/>
</controls>
</pages>
<compilation debug="true">
:
</compilation>
<httpHandlers>
:
</httpHandlers>
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35"/>
<add name="Session" type="System.Web.SessionState.SessionStateModule"/>
</httpModules>
<!-- Enable in-process session state for application -->
<sessionState mode="InProc" cookieless="false" timeout="20"/>
</system.web>

Thank you.

"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
re:
!How can I use the Session ?

Why don't you try a simple web.config, like :

------------------------------------------------------------
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<pages enableSessionState = "true" />
<compilation debug="true" />
<sessionState mode="InProc" cookieless="false" timeout="20" />
</system.web>
</configuration>
----------------------------------------------------------

Check to see if it works, and then add other configuration
attributes until you find the one which is interfering ?

To check whether it's working or not, in any page, in Page_Load, set a
session variable :

---------------------------------------------
<%@ Page Language="VB" %>
<script language="VB" runat="server">
Sub Page_Load(Sender As Object, E As EventArgs)
Session("somevar") = "somevalue"
SessionState.Text = Session("somevar")
End Sub
</script>
<html>
<head>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label id="SessionState" runat="server"/></asp:Label<br />
</div>
</form>
</body>
</html>
-----------------

...and retrieve the value in a Label in the same page.

In this example, if Session is working, you'll see the text "somevalue"
returned.


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"fniles" <fn****@pfmail.comwrote in message
news:Oc**************@TK2MSFTNGP05.phx.gbl...
>>I am using Visual Studio 2005. In my ASPX page, when I try to use Session,
I got the 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>\<httpModulessection in
the application configuration."
In my Web.config I put the following, but still I got the error above:

<system.web>
<pages autoEventWireup="true" enableSessionState="true"
enableViewState="true" enableViewStateMac="true" smartNavigation="true"
validateRequest="false">
<controls>
<add tagPrefix="asp" namespace="System.Web.UI"
assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35"/>
</controls>
</pages>
<compilation debug="true">
:
</compilation>
<httpHandlers>
:
</httpHandlers>
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35"/>
<add name="Session" type="System.Web.SessionState.SessionStateModule"/>
</httpModules>
<!-- Enable in-process session state for application -->
<sessionState mode="InProc" cookieless="false" timeout="20"/>
</system.web>

How can I use the Session ? Thank you.


Jun 1 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.