Cleaning up sessions
-
We're in the process of moving from one web server to a web farm. The load balancing is set up, and all the code adjustments (so far still using classic ASP) have been made to store a session id in a cookie, and then store all user information for that session in a SQL Server table. It's working great, and we have code that runs every so often to check for expired sessions in the DB. If a user logs off nicely using the appropriate button the session is cleaned up by code. However, we'd like to force this for times where a user closes down the browser, or browses to another site without logging off. We've played a little with "window_onbeforeunload()" but the problem is it also fires when navigating within our own site. Any suggestions on what to use for this? Thanks :)
Look at the world about you and trust to your own convictions. - Ansel Adams
Meg's World - Blog Photography - The product of my passion -
We're in the process of moving from one web server to a web farm. The load balancing is set up, and all the code adjustments (so far still using classic ASP) have been made to store a session id in a cookie, and then store all user information for that session in a SQL Server table. It's working great, and we have code that runs every so often to check for expired sessions in the DB. If a user logs off nicely using the appropriate button the session is cleaned up by code. However, we'd like to force this for times where a user closes down the browser, or browses to another site without logging off. We've played a little with "window_onbeforeunload()" but the problem is it also fires when navigating within our own site. Any suggestions on what to use for this? Thanks :)
Look at the world about you and trust to your own convictions. - Ansel Adams
Meg's World - Blog Photography - The product of my passionAhh, an age-old question...that's never been answered. Short of using a plugin (BHO, which isn't site-specific like an embedded ActiveX control), there's really no way to tell when a user leaves your site. As for closing, the same applies. One word of warning, the Window object is created for each request, so window.onbeforeunload() (et. al.) will most definitely fire each time, as you have noticed. The
IWebBrowser2
's window isn't theIHTMLWindow2
(or 3 or 4).-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----
-
We're in the process of moving from one web server to a web farm. The load balancing is set up, and all the code adjustments (so far still using classic ASP) have been made to store a session id in a cookie, and then store all user information for that session in a SQL Server table. It's working great, and we have code that runs every so often to check for expired sessions in the DB. If a user logs off nicely using the appropriate button the session is cleaned up by code. However, we'd like to force this for times where a user closes down the browser, or browses to another site without logging off. We've played a little with "window_onbeforeunload()" but the problem is it also fires when navigating within our own site. Any suggestions on what to use for this? Thanks :)
Look at the world about you and trust to your own convictions. - Ansel Adams
Meg's World - Blog Photography - The product of my passionWelp one way I can think of getting the same end result is to set the session expiration to a really low number, like 2 minutes, and then have a mechanism in each page that keeps the session alive as long as the person has the browser open and on that site (regardless if they are idle or not). I usually do this by having an iframe in every page that points to a page that grabs the system time every minute using a meta refresh tag. A javascript refresh would also work in this scenario.
-
Welp one way I can think of getting the same end result is to set the session expiration to a really low number, like 2 minutes, and then have a mechanism in each page that keeps the session alive as long as the person has the browser open and on that site (regardless if they are idle or not). I usually do this by having an iframe in every page that points to a page that grabs the system time every minute using a meta refresh tag. A javascript refresh would also work in this scenario.
I had to deal with a similair issue yesterday and here is what I did.. Situation, Users log in and we adjust their profile to show them as "Logged In", which allows us to produce an accurate list of "Current Users". Whne a users logs off (using the "defined" method, which is a button), then we update their profile to show them as "Logged off". When user logs in when user logs off, we capture the time of these two events and we produce a report of "Time Using System". Well, as you are now seeing, users dont always use your "buttons". So what I did was add a Log-Off catch in the Session_OnEnd section of the global.asa like so: Sub Session_OnEnd ' Decrement the current number of active users Application.Lock Application("CurrentUsers")=Application("CurrentUsers")-1 Application.Unlock ' Close the current users open session and adjust DB set conn = server.createObject("adodb.connection") conn.open("Server=SQLServer.petcarefinder.com;Driver={SQL Server};Database=Users_DB;UID=Username;pwd=Password;") conn.execute("dbo.con_LogUserOutOfSystem('" & Session("UID") & "')") conn.close :: set conn = nothing End Sub This only "Logs Off" the current session, it doesnt wipe out all sessions on the server. I have tested this relentlessly in the last 2 days and it seems to never not work. let me know if this would help you .... - Sage
-
We're in the process of moving from one web server to a web farm. The load balancing is set up, and all the code adjustments (so far still using classic ASP) have been made to store a session id in a cookie, and then store all user information for that session in a SQL Server table. It's working great, and we have code that runs every so often to check for expired sessions in the DB. If a user logs off nicely using the appropriate button the session is cleaned up by code. However, we'd like to force this for times where a user closes down the browser, or browses to another site without logging off. We've played a little with "window_onbeforeunload()" but the problem is it also fires when navigating within our own site. Any suggestions on what to use for this? Thanks :)
Look at the world about you and trust to your own convictions. - Ansel Adams
Meg's World - Blog Photography - The product of my passionI am with Sage, use
Session_OnEnd
, that is exactly what it is for :) regards, Paul Watson Bluegrass South Africa Miszou wrote: I have read the entire internet. on how boring his day was. Crikey! ain't life grand? -
I am with Sage, use
Session_OnEnd
, that is exactly what it is for :) regards, Paul Watson Bluegrass South Africa Miszou wrote: I have read the entire internet. on how boring his day was. Crikey! ain't life grand?Paul Watson wrote: I am with Sage, use Session_OnEnd, that is exactly what it is for Certainly Sage has answered that question :). Unfortunately being a demanding woman I want more! :-O We also have a situation where the IFA's don't realise they are actually leaving our site when they click the red "X" to close the browser. Don't ask me to explain this madness - I can't! It's merely an observation which brings us pain. Then they want to know where all their work has gone :doh:. As we've established above "window_onbeforeunload()" unfortunately not only fires when a browser is closed, but also when moving between pages. Being the demanding person I am I find myself on a quest to find an action I can fire only when the user attempts to close the browser so that I can display a confirmation box explaining to them that they are actually leaving the site, not just minimising it to go to the solitaire game behind it if they click the red "X" and close the browser :rolleyes:. Any ideas? (please don't say user education...) :)
Look at the world about you and trust to your own convictions. - Ansel Adams
Meg's World - Blog Photography - The product of my passion -
Paul Watson wrote: I am with Sage, use Session_OnEnd, that is exactly what it is for Certainly Sage has answered that question :). Unfortunately being a demanding woman I want more! :-O We also have a situation where the IFA's don't realise they are actually leaving our site when they click the red "X" to close the browser. Don't ask me to explain this madness - I can't! It's merely an observation which brings us pain. Then they want to know where all their work has gone :doh:. As we've established above "window_onbeforeunload()" unfortunately not only fires when a browser is closed, but also when moving between pages. Being the demanding person I am I find myself on a quest to find an action I can fire only when the user attempts to close the browser so that I can display a confirmation box explaining to them that they are actually leaving the site, not just minimising it to go to the solitaire game behind it if they click the red "X" and close the browser :rolleyes:. Any ideas? (please don't say user education...) :)
Look at the world about you and trust to your own convictions. - Ansel Adams
Meg's World - Blog Photography - The product of my passionwell then, like many web developers before us and many developers after us, it sounds to me like it is time to take a hint from a porn site or warez site. I dont know how many you have seen (not that I look at porn all day long or anything), but many of them have some "sticky" tricks which end up making their way into the legitimate side of the Internet. Pop-up ads are the most famous. The reason I mention this is another trick many of them have been employing for some time now is to open the browser in a fashion that none of the toolbars exist. For a user that dont know better (and dont know keyboard shortcuts), it is near impossible to close these windows. This sounds liek soemthing for you. Of course, you would need to "emulate" the minimize and close buttons, but it will help you do what you need to do. I would need to hunt down an example, but I thought I would throw the idea at you and see if it interests you. - Sage