473,325 Members | 2,805 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

How to use Session ?

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
2 16802
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Paul | last post by:
Hmmm, didn't seem to work. I have set session.use_cookies = 1 and session.use_trans_sid = 1 in my php.ini file. Index.php contains:...
2
by: Damien | last post by:
Hi to all, I'm currently re-designing our intranet : nice and lean CSS2, cleaned-up PHP 4.3.7, better-normalized MySQL ;o). So I've started using the $_SESSION variable instead of register_globals...
1
by: mudge | last post by:
I'm running PHP Version 4.3.10. I'm trying to make it so that when a person logs in using a user name and password that their session is valid and continues for a few months so they don't have to...
6
by: Al Jones | last post by:
This is a repost form the vbscript newgroup - if this isn't the appropriate group would you point me toward one that is. Basically, I seem to be losing session data part way though preparing an...
0
by: joseph conrad | last post by:
Hi, I tried to implement my own session handler in order to keep control on the process the drawback I foun it is not creating and storing in my cookie the PHPSESSID variable anymore. reading te...
14
by: aroraamit81 | last post by:
Hi, I am facing a trouble. I have some Session variables in my code and somehow my session variables are getting mixed up with other users. For example User A has access to 10 companies and...
7
by: aroraamit81 | last post by:
Well Guys, Here is a very strange trouble. When more than one users request tto same page at the same time then our session gets conflicted. Moreover I printed my SessionID, strangely but true I...
1
by: Santosh | last post by:
Dear All i am writting a code sending mail with attachement. i am writting code for sending mail in one page and code for attaching a file in the next page. aftet attaching a file i am taking...
5
by: lyealain | last post by:
<% If Session("username") = "" Then Response.Redirect("/CLS/Login.asp") End If Dim conn Dim connectstr Dim db_name, db_username, db_userpassword Dim db_server Dim res
1
by: KidQuin | last post by:
I am having problems with session value between pages. Happening in both firefox and IE7. I go between page by links so I know it's not header changes. I use session_start as the first line on the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.