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
|