p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Classic ASP Professional (http://p2p.wrox.com/forumdisplay.php?f=63)
-   -   update database when browsr close (http://p2p.wrox.com/showthread.php?t=73433)

artarasan March 19th, 2009 12:50 AM

update database when browsr close
 
Sir,

I am using ASP 3.0 and SQL SERVER 2000 in my website. I want update logout time in my database when the browser close. If i wrote in the events Onunload or Onbeforeunload means it will fire refresh, back operations also but i need only the updation when the browser close .. Please give me a best solution for this problem

Thanking You

mat41 March 19th, 2009 06:24 PM

There are some very good posts in this forum on giving yourself the best chance of doing this. I believe Imar is the persons replies you should look for. IMO Classic ASP fails in this area, at least I have never got this working personaly anyhow.... From memory you need to use a global.asa file and look at Session_OnEnd method - Given this method does not fire when the browser closes insteasd when the session ends it makes things difficult. I do recall Mr ASP (Imar) has a solution and has posted it.

Imar March 20th, 2009 01:56 PM

Quote:

but i need only the updation when the browser close ..
You can't really determine the difference between a true browser close and navigating to the next page or a completely different web site. In all cases, the browser will fire this event.

So, as Mat pointed out, you probably want to do this server side in Session_OnEnd as that's the only way to detect a user has left and not requested a new page for some time.

Cheers,

Imar

Old Pedant March 22nd, 2009 04:34 PM

Quote:

You can't really determine the difference between a true browser close and navigating to the next page or a completely different web site.
Not strictly true.

It's a pain, but you *CAN* make that determination.

Here is a very *SIMPLE* demonstration:
Code:

<script>
var goingAway = true; // assume the worst

function sayGoodbye( )
{
    if ( goingAway ) alert("Leaving so soon?  Sorry to see you go.");
}
</script>
<body onunload="sayGoodbye();">
<a href="www.google.com">visit google</a>

<form action="anotherPageOnThisSite.html" onsubmit="goingAway=false; return true;">
Give me your name: <input name="name">
<input type=submit value="Log in">
</form>

Do you see it?? You just need to make sure that EACH AND EVERY WAY that a person might navigate to another page on your site sets the goingAway flag to false and then the logic in ONUNLOAD (and it could be in ONBEFOREUNLOAD) can ignore those moves while capturing all others.

Now, it's still not perfect. The user can simply kill the browser (e.g., with the task manager) or could lose connection (modem goes dead) and you'll never *get* the unload event. So you still should have the backup of Session.OnEnd in global.asa or equivalent. But used with care you *can* capture the majority of all cases you need to catch.

mat41 March 22nd, 2009 06:58 PM

mmmm I do like reading posts on this topic. Sorry in advance that my opinion is not a solution for your issue, a thought and my 2 cents worth:

Over the last few years every classic ASP coder in our office has gone to .NET however I have stuck with classic ASP. Is it because im the oldest and have been there the longest or is it because I think my job is secure.....Anyhow what ever the reason this issue is about the only thing I would like to offer clients which I have not been able to with confidence. The .NET guys can do this with confidence and remind me of it when ever they can (all in good spirits of course). I have now become very good at avoiding this dreaded deliverable when it rears its, In my opinion, its ugly head.

Old Pedant March 23rd, 2009 02:08 AM

Okay, I give up. How do the ASP.NET guys do this with any more confidence than you'd have with ASP???

I, for one, have never seen a .NET-based solution. That is, not one that differs from the JavaScript one I gave above.

There's no way for ASP.NET to prevent somebody from simply typing a new URL into his/her browser.

Enlighten us. Are your mates a heluva lot smarter than the ASP.NET world, in general???

mat41 March 23rd, 2009 07:07 PM

About typing a new URL, im sure they dont have an answer for that one. In short they just remind me about the improved state management and other related tools.

Are they a 'heluva lot smarter' than guys like yourself, Imar, Doug (sorry about those other super helpful experts which dont come to mind at this moment) and co.... Not even close :o)

Old Pedant March 23rd, 2009 07:51 PM

Yeah, but there's not one of those advanced .NET tools you can't do yourself. Well, to be fair, many of them would require writing a component for ASP. Resizing images comes to mind immediately. But you could even do cookieless sessions in ASP if you really wanted to. I believe that the old Barnes & Noble (booksellers) site did so, when it was written in ASP years ago.


All times are GMT -4. The time now is 06:55 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.