Solved

capture closing event of a browser, then execute ASP code

Posted on 2004-08-17
5
210 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

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 informatio…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

696 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