session state not sticking
Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=25890
Printed Date: 29 March 2026 at 7:36pm Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com
Topic: session state not sticking
Posted By: carrathanatos
Subject: session state not sticking
Date Posted: 26 June 2008 at 3:11pm
When I set my session variables, and then move to the next page with my new found credentials, it doesn't keep them.
I'm moving from login.asp using check.asp which should bring me to panel.asp.
login.asp:
<html> <head> <title>Login</title> </head> <body> <% Session.Abandon %> <form name="form" action="check.asp" method="post"> Username: <input type="text" name="username" /> Password: <input type="password" name="password" /> <input type="hidden" name="login" value="true" /> <input type="submit" value="login" /> </form> </body> </html>
|
check.asp:
<% Dim adoCon Dim rsLogin Dim strSQL Dim username Dim passwordForm Dim passwordDB
Session.Abandon username = Request.Form("username") passwordForm = Request.Form("password")
Set adoCon = Server.CreateObject("ADODB.Connection") adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("login.mdb") Set rsLogin = Server.CreateObject("ADODB.Recordset") strSQL = "SELECT tblLoginInfo.ID_no, tblLoginInfo.loginName, tblLoginInfo.loginCode, tblLoginInfo.permissionLevel, tblLoginInfo.fName, tblLoginInfo.lName FROM tblLoginInfo;" rsLogin.Open strSQL, adoCon
Do While (not rsLogin.EOF) AND (rsLogin("loginName") <> username) rsLogin.MoveNext Loop if(rsLogin("loginCode") = passwordForm) Then ENABLESESSIONSTATE = TRUE response.write("pass") Session("timeVisited") = Time() Session("permission") = rsLogin("permissionLevel") Session("name1") = rsLogin("fName") Session("name2") = rsLogin("lName") response.write(session("permission")) response.write(session("name1")) response.write(session("name2")) response.write(session.timeout) response.redirect "panel.asp" else response.write("fail") end if
Session.Abandon
rsLogin.Close Set rsLogin = Nothing Set adoCon = Nothing
%> <!-- Link to test session state: <a href="session.asp">session</a> -->
|
panel.asp:
<% If IsEmpty(Session("name1")) then response.redirect "login.asp" end if %>
<html> <head> <title>Job Opportunities Panel</title> <link rel="stylesheet" type="text/css" href="m1-5.css" /> </head> <body>
<table id="maintable" align="center"> <tr> <td colspan="2" height="50" id="banner"> <img src="jobBanner.png" /> </td> </tr> <tr > <td height="400" id="navigation" valign="top" align="left">
Hello (username)<br> Logout<br> Change Password<br> <a href="add.asp">Add New Posting</a>
</td><td id="content" valign="top" align="left"> <% Dim adoCon Dim rsJobs Dim strSQL Dim itemID
Set adoCon = Server.CreateObject("ADODB.Connection") adoCon.Open = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("jobOps.mdb") Set rsJobs = Server.CreateObject("ADODB.Recordset") strSQL = "SELECT tblJobs.ID_no, tblJobs.jobTitle, tblJobs.jobLocation, tblJobs.jobSalary, tblJobs.payType FROM tblJobs;" rsJobs.Open strSQL, adoCon
Do While not rsJobs.EOF Response.Write("<br />") Response.Write(rsJobs("jobTitle")) Response.Write(" (") Response.Write(rsJobs("jobLocation")) Response.Write(") - ") Response.Write("<a href=""delete_entry.asp?ID=" & rsJobs("ID_no") & """>Delete</a>") Response.Write(" | ") Response.Write("<a href=""update_form.asp?ID=" & rsJobs("ID_no") & """>Edit</a>") Response.Write("<br />Pay: ") Response.Write(rsJobs("jobSalary")) Response.Write("/") Response.Write(rsJobs("payType")) Response.Write("<br />") Response.Write("<hr width=""80%"" height=""1"" />") Response.Write("<br />") rsJObs.MoveNext Loop
rsJobs.Close Set rsJobs = Nothing Set adoCon = Nothing %> </td></tr></table> </body> </html>
|
I have checked on my server and session states are enabled. I am using Firefox and cookies are enabled.
I can't find any other resources out there to troubleshoot this, so maybe you guys can help... 
|
Replies:
Posted By: WebWiz-Bruce
Date Posted: 26 June 2008 at 3:34pm
You want to remove the Session.Abandon part as this drops any sessions that are currently running for your web site loosing any data that they hold. Session.Abandon should always be avoided.
If you need to destroy a session variable after you finish using it use:-
Session.Contents.Remove("Variable_name_here")
------------- https://www.webwiz.net/web-wiz-forums/forum-hosting.htm" rel="nofollow - Web Wiz Forums Hosting https://www.webwiz.net/web-hosting/windows-web-hosting.htm" rel="nofollow - ASP.NET Web Hosting
|
Posted By: carrathanatos
Date Posted: 26 June 2008 at 4:24pm
|
nevermind, I figured it out... I took out the session.abandon in check.asp, because while I thought I was clearing any existing sessions, it actually doesn't take effect until the next page... effectively erasing my session.
|
|