Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 7th, 2004, 08:47 PM
Registered User
 
Join Date: Dec 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Having trouble with Maintaining Session State

Hi all,

I am at a lose at what can possibly be wrong. I have a page where a user can log in, which then redirects to a members page. For some reason, if the user leaves that members page, the session state is not maintained. I have tried unsuccessfully figuring out what the problem is.

This is one of the include files that is on each page:

Session.asp
*********************
<%
' debugging information
    Dim strDebug
    strDebug = "<p>Before Request = " & Request.ServerVariables("REQUEST_METHOD") & "<br>" & vbCrLf
    strDebug = strDebug & "State = " & Session("logged_state") & "<br>" & vbCrLf
    strDebug = strDebug & "UserID = " & Request.Cookies("UserID") & "<br>" & vbCrLf
    strDebug = strDebug & "txtUserID = " & Request.Form("txtUserID") & "</p>" & vbCrLf
    Response.Write strDebug
'
' set up objects and variables
    Dim myConn, myRst, UserID, UserPW
    Set myConn = Server.CreateObject("ADODB.Connection")
    Set myRst = Server.CreateObject("ADODB.Recordset")
'
' determine state of the session
    If Session("logged_state") <> "IN" Then
        Session("logged_state") = "OUT"
    End If
    If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
        UserID = Request.Form("txtUserID")
        UserPW = Request.Form("pwdUserPassword")
    Else
        UserID = Request.Cookies("UserID")
        UserPW = Session("user_password")
    End If
    If UserID = "" Then
        UserID = "USER ID"
        UserPW = "........"
    End If
'
' open a connection to the data base
    myConn.Provider = "Microsoft.Jet.OleDb.4.0"
    myConn.ConnectionString = Server.MapPath("/CustomerSupport/db/Project1104.mdb")
    myConn.CursorLocation = adUseClient
    myConn.Open
'
' retrieve the user record and associated organization info
    myRst.ActiveConnection = myConn
    myRst.CursorLocation = adUseClient
    myRst.CursorType = adOpenDynamic
    myRst.LockType = adLockReadOnly
    myRst.Open "Select t1.*, t2.* " & _
            " From [Users] As t1" & _
            " Left Join [Organization] As t2" & _
            " On t1.OrgID = t2.OrgID" & _
            " Where t1.UserID = '" & UserID & "';"
'
' determine if record found and user/password are correct
    Session("logged_state") = "OUT"
    If Not myRst.EOF Then
        If myRst.Fields("UserID").Value = UserID _
        And myRst.Fields("Password").Value = UserPW Then
            Session("logged_state") = "IN"
            UserID = myRst.Fields("UserID").Value
            UserPW = myRst.Fields("Password").Value
        End If
    End If
    If Session("logged_state") <> "IN" Then
        UserID = "USER ID"
        UserPW = ""
    End If
'
' save user and password information
    Response.Cookies("UserID") = UserID
    Response.Cookies("UserID").Expires = DateAdd("yyyy", 1, Now())
    Response.Cookies("UserID").Path = "/"
    Response.Cookies("UserID").Secure = True
    Session("user_password") = UserPW
'
' debugging information
    strDebug = "<p>After Request = " & Request.ServerVariables("REQUEST_METHOD") & "<br>" & vbCrLf
    strDebug = strDebug & "State = " & Session("logged_state") & "<br>" & vbCrLf
    strDebug = strDebug & "UserID = " & UserID & "<br>" & vbCrLf
    strDebug = strDebug & "myRst.EOF = " & myRst.EOF & "</p>" & vbCrLf
    Response.Write strDebug
%>
**************************

And this is the form portion of the other include file located on each page:

***************************
<form name="ClientLogOn" method="POST" action="../CustomerSupport/MembersOnly.asp" >
            <td width="776" align="right" colspan="5"><img src="<%=sitePath%>img/img_clientLogOn.gif" width="66" height="15" alt="" border="0">
            <input class="cssLight" type="text" name="txtUserID" id="txtUserID" size="15" maxlength="15" value="<%=UserID%>"
             onFocus="this.value = (this.value=='USER ID') ? '' : this.value;"
             onBlur="this.value = (this.value == '') ? 'USER ID' : this.value;">
            <img src="<%=sitePath%>img/shim.gif" width="2" height="1" alt="" border="0">
            <input class="cssLight" type="password" name="pwdUserPassword" id="pwdUserPassword" size="15" maxlength="15" value="........"
             onFocus="(this.value=='........') ? this.value='' : this.value=this.value;"
             onBlur="(this.value == '') ? this.value='.......' : this.value=this.value;">
            <img src="<%=sitePath%>img/shim.gif" width="5" height="1" alt="" border="0">
            <input type="image" src="../img/img_arrow.gif" width="7" height="9" alt="Log In" border="0">
            <img src="../img/shim.gif" width="5" height="1" alt="" border="0">
        </form>

*********************************

Can anyone give any insight as to why this isn't working?

Thanks so much in advance!

Kellie








Similar Threads
Thread Thread Starter Forum Replies Last Post
maintaining session state in C# grs General .NET 0 January 13th, 2005 03:46 AM
Maintaining State in Tables MikeSchnell ASP.NET 1.0 and 1.1 Basics 1 March 25th, 2004 01:22 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.