There are many ways, which none of them are desireable. I will list out what I learn.
Note: I hope people understand this. Most people assume I want to logout only when client close browser. That's not the case, I just want to free up resources instead of 20minute lag. Most devs just upgrade computer I guess.
1) Keep ping your server from client script, thus, it will keep the "short session" alive.
This is obviously will increase traffic to your server and it will obviously not logout instantly as you don't want to ping like every second.
2) Use Javascript from client broswer. So far, I don't think any of them is working, even the existing example of IE code, the clienX will be > 0. Anyway, here is the code that works for me so far. Only on IE since Firefox event is not working for me right now. I roughly calculated the position of the close button relatively on the screen and determine if client clicked i that area. If refresh button is too close to close button (x wise), it will think you clicked close button, but, that's a rare case.
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function test(event) {
var X = window.event ? window.event.screenX : event.clientX;
// IE only because event.clientX for FF = undefined (event.clientX IS the FF way).
if (X == null) {
alert("No X");
return;
}
var left = window.screenLeft ? window.screenLeft : window.screenX;
var winwidth = document.body.clientWidth ? document.body.clientWidth : window.outerWidth;
var leftMargin = document.body.leftMargin ? parseInt(document.body.leftMargin, 10) : 0;
var rightMargin = document.body.rightMargin ? parseInt(document.body.rightMargin, 10) : 0;
var resultX = X - (window.screenLeft + winwidth + leftMargin + rightMargin); // scroll bar width is not calculated.
var Y = window.event ? window.event.clientY : event.clientY;
if (resultX > -25 && Y < 0)
alert("logging out");
};
</script>
</head>
<body onbeforeunload="test(event);">