How to use Session ?

F

fniles

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>\<httpModules> section 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.
 
J

Juan T. Llibre

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>
 
F

fniles

Thank you.
I needed the other stuffs in the web.config because I am using AJAX.
I fixed the problem by making the <pages> simpler 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.
 

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,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top