|
-
Jul 26th, 2004, 01:49 AM
#1
Thread Starter
Frenzied Member
Session_End and Page_unload?
I have a strange problem. I update a flag in my database when a user is logging in.
Code:
Sub ConnectUser(ByVal userName As String)
strUserCn = "Provider=Microsoft.jet.oledb.4.0;Data Source=" & Server.MapPath("login.MDB") & ";"
Dim strSql As String = "update Person SET Online='Yes', LastLogin='" & CDate(Date.Now) & _
"', Logins=" & CInt(Session("NoOfLogins") + 1) & " WHERE UserName='" & userName & "'"
Dim objConnection As New OleDbConnection(strUserCn)
Dim objCommand As New OleDbCommand(strSql, objConnection)
Dim objDataReader As OleDbDataReader
objConnection.Open()
objCommand = New OleDbCommand(strSql, objConnection)
objCommand.ExecuteNonQuery()
objConnection.Close()
End Sub
This works fine, the flag is updated and the value is 'Yes'.
But then I implement this code, for setting the value to 'No', when the user terminates the session:
Code:
Private Sub Page_Unload(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Unload
clsUserLogin1.DisconnectUser(Session("username"))
End Sub
where
Code:
Sub DisconnectUser(ByVal userName As String)
strUserCn = "Provider=Microsoft.jet.oledb.4.0;Data Source=" & Server.MapPath("login.MDB") & ";"
Dim strSql As String = "update Person SET Online='No' WHERE UserName='" & userName & "'"
Dim objConnection As New OleDbConnection(strUserCn)
Dim objCommand As New OleDbCommand(strSql, objConnection)
Dim objDataReader As OleDbDataReader
objConnection.Open()
objCommand = New OleDbCommand(strSql, objConnection)
objCommand.ExecuteNonQuery()
objConnection.Close()
End Sub
When I have logged in and investigates the value in the database I see that the value is 'No' right after I have loaded the application??? What is happening? I know that I could make a "Logout" button, but it would be great if this could work.
-
Jul 26th, 2004, 10:57 AM
#2
Fanatic Member
The best place to put this code would be in your Session_Start and Session_End events of your global file in the root.
-
Jul 26th, 2004, 11:27 AM
#3
Originally posted by venerable bede
The best place to put this code would be in your Session_Start and Session_End events of your global file in the root.
Yep. Page_unload is just part
of the page life cycle and will get called everytime a request is made, hence why your flag is always set to no when you check it.
-
Jul 27th, 2004, 01:10 AM
#4
Thread Starter
Frenzied Member
Great, thanks I will try that.
-
Jul 27th, 2004, 06:52 AM
#5
Fanatic Member
Originally posted by Fishcake
Yep. Page_unload is just part
of the page life cycle and will get called everytime a request is made, hence why your flag is always set to no when you check it.
My God fishcake !
Did I actually offer good advice for a change ?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|