Solved

capture closing event of a browser, then execute ASP code

Posted on 2004-08-17
5
208 Views
Last Modified: 2008-03-10
I have this page where a user logs in and I tag in the database that is he is logged. I use cookies (session when cookies are disabled) to log the user in and the tag in the database is simply a "restriction". I need this feature because only one user should be allowed to log in at a time, and his account cannot be used by the others from different PC. So, when another user logs in the same account, and this account is tagged as logged in in the db, he won't be allowed to enter the site.

The thing is,  when the logged user closes his browser window without logging out, the tag in the database as loggedin won't be reset. Therefore, the next time he logs in, he won't be allowed to since he's tagged in the database. I can't use Session_OnEnd because it's not fired by my server.

I'm looking into capturing the closing event of the browser window then, but I'm clueless about how to implement this. A lot suggested I used body onUnLoad in js but this is always raised when I change pages -- and I just want to capture the closing event. Once I captured it then I will run the ASP code where the user will be tagged as logged out in the database.

Any idea how I'd go about this problem?
0
Comment
Question by:ludy
5 Comments
 
LVL 46

Assisted Solution

by:fritz_the_blank
fritz_the_blank earned 50 total points
ID: 11826913
I am afraid that the onUnLoad() makes no distinction between navigating to another page, using the x to quit, alt-f4, menu exit and etc. So essentially it is of no use (even if you put it in a frame so you can capture when the site is left).

The only thing that you can do is to make an entry into the database each time that a page is visited, and then you can assume that 20 minutes after the last entry, the session has expired.

FtB
0
 
LVL 9

Expert Comment

by:leechoonhwee
ID: 11827325
Use global.asa

<SCRIPT LANGUAGE=VBScript RUNAT=Server>
Sub Session_OnEnd
'Add your Session_OnEnd code here
End Sub
</SCRIPT>
0
 
LVL 5

Expert Comment

by:LlamaJoe
ID: 11827497
I have done very similar work by using application variables, rather than session variables, as the session would not be accessible by the user logging in on another pc, but the application variables would.

The general sense, in session_onStart check an application variable (make it an array, or custom object, or whatever - it doesn't have to be a string) and store the status of all logged in users -  make sure that the session_onEnd event removes the user from the object - then if a user tries to log in from another machine, it will say that you are already logged in, so wait until the session is available - if it is the same user trying to log in, ask for credentials, and then delete the other instance of the user in the application variable - you will have to include a piece of code on every page to check to make sure that the current user is still valid in the application variable.

or, move to .net and use security pricipals..... enjoy!
0
 

Author Comment

by:ludy
ID: 11827723
I can't use global.asa because session_onend isn't fired up. :-(
0
 
LVL 26

Accepted Solution

by:
Rejojohny earned 50 total points
ID: 11827837
ur problem would not anyway get solved by getting "closing" event .. what happens if the user's browser crashes or he moves to another site in the same window? Better would be to have an application varibale with the current user list and the last page logged accessed time .. this can be updated everytime the user accesses a particular page .. so if the user does not "logout" and closes the browser, the next time he tries to access the applicaiton within 20 minutes, he would still be present in the application variable and so would be rejected a new connection .. lets say u decide on 20 minutes as the timeout period .. so after 20 minutes when he tries to access the applicaiton again, he would still be there in the applicaiton variable but as 20 minutes has passed, his request would be processed ...
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SP to delete duplicates 15 72
ASP Focus problem 3 67
How to show result of a NULL value at random? 33 57
Button to go back 3 28
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question