Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > Classic ASP Databases
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 16th, 2004, 12:09 PM
Authorized User
 
Join Date: Jul 2004
Location: , , .
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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


Reply With Quote
  #2 (permalink)  
Old July 16th, 2004, 08:53 PM
Friend of Wrox
 
Join Date: Sep 2003
Location: Mentiri, Muara, Brunei.
Posts: 363
Thanks: 0
Thanked 1 Time in 1 Post
Default

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
   .....

%>




Reply With Quote
  #3 (permalink)  
Old July 17th, 2004, 09:01 AM
Authorized User
 
Join Date: Jul 2004
Location: , , .
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.


Reply With Quote
  #4 (permalink)  
Old July 17th, 2004, 10:54 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

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
Reply With Quote
  #5 (permalink)  
Old July 18th, 2004, 08:13 AM
Authorized User
 
Join Date: Jul 2004
Location: , , .
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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


Reply With Quote
  #6 (permalink)  
Old July 18th, 2004, 10:27 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

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
Reply With Quote
  #7 (permalink)  
Old July 19th, 2004, 10:46 AM
Authorized User
 
Join Date: Jul 2004
Location: , , .
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It does help, indeed!

Thanks again, Mischa

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 03:30 PM.


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