Losing Session Variables
Posted on 2005-04-06
I have a login page which if user trys to access files inside Admin Folder they are redirected to, once authenticated a session variable is set
Session("AdminTownID") = dr.Item("Town_ID") 'Tow_ID is a an Integer from SQL DB
I can access this variable ok most of the time but ocasionally I get an error indicating variable is empty. There seems no logic to when it disappears.
Also it fails everytime if I try to add the line
Dim SqlStmt As String = "SELECT * FROM tblEvents WHERE Town_ID="& Session("AdminTownID").ToString
I get the following 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.
This happens on the listevents.aspx page which has page directive as
<%@ Page Language="VB" enableSessionState="True" ContentType="text/html" ResponseEncoding="iso-8859-1" Debug="TRUE" Src="ListEvents.aspx.vb" Inherits="TBO.Events.ListItems" %>
My Web.Config File is as follows
<allow users="*" />
<forms timeout="60" />
<sessionState cookieless="false" timeout="60" />
<deny users="?" />
I am quite new to ASP.Net and cannot understand why this variable keeps disappearing.
I have set in IIS the Session to last 60 minutes.
Any help will be most appreciated