...

View Full Version : How to kill a session when window is closed



joecool2005
01-17-2007, 05:32 PM
Hi,

On my website I have a section that can open a new window when the users click on it. When the users close the new window, my session variable are still alive. I don't know how to kill it.

I added these lines on my global.asa and the session is still alive.
function Session_OnEnd() {
Session.Contents.RemoveAll();
Session.Abandon();
}

The global.asa execute when a new window is open.

Example:

<a href="java script:void(0)" onclick="window.open('https://secure.drtax.ca/ufileshop/2006/storespec.asp')">2006</a>
<a href="java script:void(0)" onclick="window.open('https://secure.drtax.ca/ufileshop/2005/storespec.asp?taxyear=2005')">2005</a>

By clicking on both links, you will see the same year because the year is a session variable. It's supposed to show 2006 on one page and the other 2005.

How can I fix it?
Thx
Joe

Spudhead
01-18-2007, 11:14 AM
I'm not entirely clear about your application logic - it sounds a bit like you might need to use two session variables? And in any case, your session shouldn't end if the original browser window is still open.

That said, the issue of Session_OnEnd not firing reliably when the user closes their browser is one I've come up against before, and it's a bit of a pain. You can use Response.IsClientConnected (http://www.devguru.com/technologies/asp/9152.asp) to check if they're still there, but how and when you check is really dependent on your application structure. I've also seen solutions that mirror sessions using the database - it's a bit complex though.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum