|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Global.asa urgently need help
Hi;
I wrote global.asa file but I couldn't get what I expect.After user logs on to the system,if he/she directly closes the explorer,the time he/she logs out must be written to the database.I have logout.asp file which do this when the user click on the LOGOUT button,but if the user doesn't click it just closes the explorer what handles it??The following global.asa tries to do that but I think there is something wrong.If you examine it I would be very happy thanks... GLOBAL.ASA <script language=vbscript runat=server> Sub Application_OnEnd() session.abandon() End Sub Session.Timeout=1 Sub Application_OnStart() Application("CurrentUser" )=0 Application("TotalUser" )=0 End Sub Sub Session_OnEnd() Application("CurrentUser" )=Application("CurrentUser" )-1 Application("TotalUser" )=Application("TotalUser" )-1 Set con = Server.CreateObject("ADODB.Connection" ) con.Open "DSN=Address" SQL="UPDATE tblLog SET fldTimeOut= "' & Time() & "' WHERE fldUserName= "' & Session("Admin" ) & "'" con.execute(SQL) session.abandon() con.close End Sub Sub Session_OnStart() Application("CurrentUser" )=Application("CurrentUser" )+1 Application("TotalUser" )=Application("TotalUser" )+1 End Sub </script> |
|
#2
|
|||
|
|||
|
Unfortunately, the server has no idea when or if the user closes the browser. So, if the user doesn't use the log out feature and just closes the browser, their session won't end until it times out 20 minutes later.
|
|
#3
|
|||
|
|||
|
what should be done ?
so in this case what should I do?
I set timeout to 1 ?? By the way thank you for your reply |
|
#4
|
|||
|
|||
|
if you set the timeout to 1, it means that a user who looks at a page in the application for longer than 1 minute, and clicks a link or submits a form in the application -- which are all valid events -- will experience timeout. This will force a session_onEnd and a subsequent session_onStart, so your application visitor totals will very quickly be out of wack.
I did not see a signon routine in your session_onStart, but I suppose you check every page in the application for Session("admin"). Mind you the scenario I described above, will also reset value of Session("admin"). Coming back to your original question: unfortunately, the way the session_onEnd works is by design. Closing the browser, even navigating to another website (outside of the realm of your webapplication) will not force a Session.Abandon, but the Session waits until timeout to write values to the database. I wrestled myself with the same issue and could not come up with a satisfactory answer using the global.asa events.
__________________
- Rogier Doekes |
|
#5
|
||||
|
||||
|
What about using javascript to detect when the browser is being closed, then calling the logout script when this occurs?
|
|
#6
|
|||
|
|||
|
re:java script
ohh that's a good idea I think.I'll try that
I think I have to write a java script but where am I going to call this script ?? Thank you so much ) |
|
#7
|
||||
|
||||
|
By using the onUnload event handler.
http://devedge.netscape.com/library...rs.html#1121231 e.g. <body onUnload="logoutUser.asp"> |
|
#8
|
|||
|
|||
|
ok
For example the user stayed more than 20 minutes on a page doing nothing how can I give the message time expired etc etc...
|
|
#9
|
||||
|
||||
|
You can set the page to auto-refresh (using the refresh meta tag) after 20min. Your code should check once it's reloaded that the user has been authenticated (or not, as the case may be).
Alternatively, you can do nothing, and just wait till the user clicks a link or something, and then notify them of their session timeout. |
|
#10
|
|||
|
|||
|
re
thanks so much
) |
![]() |
| Viewing: Dev Articles Community Forums > Programming > ASP Development > Global.asa urgently need help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|