Solved

capture closing event of a browser, then execute ASP code

Posted on 2004-08-17
5
207 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Issue with Loop 4 58
SQL Server Web Traffic Limitations 4 61
ASP Classic - Load test 2 49
Scheduled IIS .Net2 AppPools recycle and SQL connection Hangs 33 114
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 …
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

803 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