Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

capture closing event of a browser, then execute ASP code

Posted on 2004-08-17
5
Medium Priority
?
213 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 150 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 150 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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
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 course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

610 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