 |
| Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. 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 Databases 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
|
|
|
|

July 16th, 2004, 12:09 PM
|
|
Authorized User
|
|
Join Date: Jul 2004
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Setting a DB value on Session Abandon
Hello,
I am trying to reset a field in the data base called âIsOnLineâ back to âfalseâ when the session is abandoned. For testing purposes I have a page âAbandonSession.aspâ with a single line of asp code:
Session.Abandon
The relevant portion of my global.asa file reads:
Sub Session_OnEnd
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open "DSN=FPCDSN"
Const adOpenKeyset = 1
Const adLockPessimistic = 2
Const adCmdText = 1
Set oRSuser = Server.CreateObject("ADODB.Recordset")
oRSuser.Open "SELECT * FROM UserData WHERE UserName='bigmish'", oConn, adOpenKeyset, adLockPessimistic, adCmdText
oRSuser("IsOnLine") = false
oRSuser.Update
oRSuser.Close
Set oRSuser = Nothing
End Sub
This works fine BUT only if I reload the page twice! So it goes like this: first I go to AbandonSession.asp, look at the DB table, IsOnLine is still true. I hit reload IsOnLine is still true. I hit reload a second time, now IsOnLine is false. Obviously I canât have my users reloading the log off page twice â whatâs going on? How can I fix this?
Thanks in advance, Mischa
|
|

July 16th, 2004, 08:53 PM
|
|
Friend of Wrox
|
|
Join Date: Sep 2003
Posts: 363
Thanks: 0
Thanked 1 Time in 1 Post
|
|
hello,
It looks OK. But do the processing in seperate file instead at global.asa
when u click logoff, transfer to abandon.asp The code there is...
<%response.expires=-1%>
<%
dim conn
.....
.....
sql="update userdata set isonline='false' where username='bigmish'
'i dont know the datatype of isonline.
conn.execute sql
.....
%>
|
|

July 17th, 2004, 09:01 AM
|
|
Authorized User
|
|
Join Date: Jul 2004
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Rajani,
Thanks for your help, I got it working.
I kept the DB change portion of the code in global.asa (I need it there if a user doesnât log of and is timed out; I still need to edit the DB).
As per your suggestion I added <%response.expires=-1%> to the abandon page and it fixed the problem! Looks like it was a caching issue.
|
|

July 17th, 2004, 10:54 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Hi bigmish,
Quote:
|
quote:I need it there if a user doesnât log of and is timed out; I still need to edit the DB
|
For this, you can write this code on the page where you would tell the user that he is LOGGED OFF/SESSION EXPIRED.
If session expires, and when the user still tries to play around the pages, in all pages you would be checking for the value of a session variable. If that is expired, then you would redirect the user to a page that says, "session expired. Re-Login"
On other case, if the user decides to log off, and after log off button clicked, you would redirect the user to a page where you say, "You are successfully logged off."
I believe that you use the same page for displaying the user about the current status(logged off/session expired) in both the above cases. So I would prefer you write this part of the CODE that updates the DB about his status ISONLINE=FASLE on that page. If that is abandon.asp then you don't have to change anything else.
Assuming, anytime the session expires, you redirect the user to abandon.asp and anytime he logs off, again you redirect to abandon.asp
Hope that helps.
Cheers!
_________________________
- Vijay G
Strive for Perfection
|
|

July 18th, 2004, 08:13 AM
|
|
Authorized User
|
|
Join Date: Jul 2004
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks again for replies. I few follow ups:
1. You seem to want to keep the DB edit code out of global.asa and on abandon.asp, why?
2. Your solution sounds like a good one, however, it sounds like if a session timed out, the user wouldnât be redirected to abandon.asp until they made a request. This wouldnât work so well for me: that DB field âisOnLineâ is realy for other users of the site. It is used to see if the other user is âon the siteâ. So if it doesnât change the DB until after they make a request (after time out), it would erroneously appear that they were âon the siteâ and thus available for chat.
.m
|
|

July 18th, 2004, 10:27 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Quote:
|
quote:I hit reload IsOnLine is still true. I hit reload a second time, now IsOnLine is false.
|
Is there anywhere else you are manipulating the ISONLINE value to FALSE so that you see it changed after the second refresh?
Never keep the user on the same page where you used the session.ABANDON method. It is always a good practice to redirect the user to a different page when you do such activities so as to prevent the user from hitting RELOAD again and again and see something wierd there.
1) That is due to the limitations of global.asa. What if I create 1000s of objects while going out. The onEnd handlers only have access to the Application, Session and Server objects and even in the Server object, the CreateObject and MapPath methods are not available. This is to prevent a situation where you create a whole bunch of objects and store them in the Application object on your way out. So you can't use server.createobject there which wouldn't work as expected.
2) I think the above should also answer your second query too.
Also how do you manage to set that FALSE, if I prefer not to log off and close the browser, which does not trigger a Session_OnEnd event until the SESSION_TIMEOUT is reached.
IMO, don't consider a user OFFLINE unless he explicitly hits the LOG OFF button. Additionally to handle other case, you can store the user's IP address in the DB and time_of_last_request_came_In and see if that exceeds more than say 30 mins, you can discard that record and set that user as OFFLINE, in case the user refuses to hit LOG OFF button before closing the browser. Update the time for every request (but doing this for every page, hits the DB and page load would consume time too). For discaring those records you have to run some scheduled job, but Access doesn't have facility to run scheduled jobs. So you could think of creating an application that does this.
Hope that helps
Cheers!
_________________________
- Vijay G
Strive for Perfection
|
|

July 19th, 2004, 10:46 AM
|
|
Authorized User
|
|
Join Date: Jul 2004
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
It does help, indeed!
Thanks again, Mischa
|
Similar Threads
|
| Thread |
Thread Starter |
Forum |
Replies |
Last Post |
| session.abandon() |
sarah lee |
ASP.NET 1.0 and 1.1 Basics |
4 |
December 11th, 2006 06:10 PM |
| Session.Abandon problem |
r_ganesh76 |
General .NET |
13 |
October 4th, 2004 11:20 PM |
| session.abandon!! |
cici |
Classic ASP Professional |
1 |
April 16th, 2004 12:48 PM |
|
 |