?
Solved

Losing Session Variables

Posted on 2005-04-06
8
Medium Priority
?
3,177 Views
Last Modified: 2008-01-09
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

<system.web>
        <authorization>
               <allow users="*" />
        </authorization>
       <authentication mode="Forms">
               <forms timeout="60" />
      </authentication>
<sessionState cookieless="false" timeout="60" />
</system.web>
 
 
<location path="webAdmin">
      <system.web>
             <compilation debug="true"/>
             <authorization>
                     <deny users="?" />
              </authorization>
      </system.web>
</location>
</configuration>

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

Cheers

Dave
0
Comment
Question by:tclgb
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 12

Expert Comment

by:laotzi2000
ID: 13721749
should be
<sessionState mode="InProc" cookieless="false" timeout="60" />
0
 

Author Comment

by:tclgb
ID: 13721795
Still 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.
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.
0
 
LVL 17

Expert Comment

by:Jesse Houwing
ID: 13722088
Is the session state disabled on one of the pages and you go from one such pages to a page that has the session enabled? Or are you going from an aspx page to an html page back to an aspx page? If you have cookieless sessions, then these two will cause the session information to disappear.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 

Author Comment

by:tclgb
ID: 13722358
No HTML switch or page where Session State disabled.

I think the problem is down to dreamweaver but cant work out why.

See:

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/ASP_DOT_NET/Q_21379343.html

I am currently downlading Visual Web Developer 2005 Express to see if that helps resolve issue at above link.
0
 
LVL 13

Expert Comment

by:davidlars99
ID: 13722627
use Cache instead of session, it's much better and reliable in many ways and by the way here's the article about asp.net state managment

http://msdn.microsoft.com/msdnmag/issues/03/04/ASPNETUserState/
0
 
LVL 12

Expert Comment

by:laotzi2000
ID: 13722930
The problem with Cache is that Cache can not guarantee the validity of the variable,
if memory is low, cached object can be released.
That's different from session.
Once you store an object in session, it is supposed to always be there.
0
 
LVL 13

Expert Comment

by:davidlars99
ID: 13722945
I think that problem can be solved by setting "slidingExpiration" property to true, not sure though  :)
0
 
LVL 1

Accepted Solution

by:
andrewh123 earned 2000 total points
ID: 13748334
I know this might bestating the obvious but I was having the same problem when I moved into asp.net until I realised what I was doing:

My session variables were disappearing simply because I was rebuilding the application after making a change, but then refreshing the page (assuming the session variable is set on a previous page).  this obviously wipes out session variables and unless you trap errors, you might get nasty error messages.

Just to be on the safe side after rebuilding my web apps now, I always go through the pages from the main entry page.

Just a thought - might be a simple answer
Andrew
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Is your organization moving toward a cloud and mobile-first environment? In this transition, your IT department will encounter many challenges, such as navigating how to: Deploy new applications and services to a growing team Accommodate employee…
Suggested Courses

599 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question