Iam using asp.net 4.0 when the user closes the browser it should clear all the session values im using master page but i have put the code in onunload event in master page when i close my radwindow(child window) it s calling onunload event but it should
happen only when the browser winodw close not in the radwindow(child window ) close.
1.bodyunload function is called but when i click child window close button it goes into the redirect logout page.hw to restrict from child window(radwindow) from browser window.redirect logout page should go only when browser window close.
2.when i redirect to logout page .it does not go to logout page.it simply stop the solution.
How do we close all the session while closing the browser ?Is it possible to have onunload or onbeforeunload event for this or smeoter approach?if not how do we achieve that? but we should not clear the session while closing radwindow(child windows) we should
do only browser window close or file menu close or tab close.
but the way i prefer to do it, is simply add to the Url a key, only with this key you will be able to acces to your session for example:
i have Session[TabCollection] so with the Key => Session[TabCollection+SessionKey] and the SessionKey is taken from the url, so when you are close the browser you can be sure that there is no way to retrieve again the session for the simple reason that
you will have to generate a new key for the user
hope that helped :)
Jeremy souffir
Please mark as Answer, if it benefits you
rajasekarand...
Member
2 Points
11 Posts
Clear all the session values when close browser in asp.net 4.0
Mar 26, 2012 08:57 AM|LINK
Hi,
Iam using asp.net 4.0 when the user closes the browser it should clear all the session values im using master page but i have put the code in onunload event in master page when i close my radwindow(child window) it s calling onunload event but it should happen only when the browser winodw close not in the radwindow(child window ) close.
var clicked = false;
function bodyUnload() {
debugger;
if (clicked == false)
//browser is closed
{
//var request = GetRequest();
//location.href="/KB/tips/LogOut.aspx";
var
request = GetRequest();
request.open("GET", "../LogOut.aspx", true);
request.send();
}
}
function GetRequest() {
var xmlHttp = null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp =
new
XMLHttpRequest();
}
catch
(e) {
//Internet Explorer
try
{
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"
);
}
catch
(e) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"
);
}
}
return xmlHttp;
}
<body onunload="bodyUnload();" onclick="clicked=true;">
Encountered problem:
1.bodyunload function is called but when i click child window close button it goes into the redirect logout page.hw to restrict from child window(radwindow) from browser window.redirect logout page should go only when browser window close.
2.when i redirect to logout page .it does not go to logout page.it simply stop the solution.
Since its an emergency issue kindly help me out.
jeremys6
Member
168 Points
35 Posts
Re: Clear all the session values when close browser in asp.net 4.0
Mar 26, 2012 09:09 AM|LINK
hey,
you have to remeber that even if you just navigate in your application to another page, the Unload will be call...
Wha exactly are you trying to do? why do you need to interfer in the onunload event?
Please mark as Answer, if it benefits you
rajasekarand...
Member
2 Points
11 Posts
Re: Clear all the session values when close browser in asp.net 4.0
Mar 26, 2012 10:03 AM|LINK
thanks for the reply
How do we close all the session while closing the browser ?Is it possible to have onunload or onbeforeunload event for this or smeoter approach?if not how do we achieve that? but we should not clear the session while closing radwindow(child windows) we should do only browser window close or file menu close or tab close.
I have global.asax file and default maste page.
thanks
jeremys6
Member
168 Points
35 Posts
Re: Clear all the session values when close browser in asp.net 4.0
Mar 26, 2012 01:47 PM|LINK
there is a couple of way to do it,
here some examples:
http://www.programmersheaven.com/mb/ASPNET/303808/303808/ending-session-when-user-close-window-/
http://dotnetfarrukhabbas.wordpress.com/2011/01/26/clear-session-on-browser-close/
http://forums.asp.net/t/1116238.aspx
http://stackoverflow.com/questions/1921941/close-kill-the-session-when-the-browser-or-tab-is-closed
but the way i prefer to do it, is simply add to the Url a key, only with this key you will be able to acces to your session for example:
i have Session[TabCollection] so with the Key => Session[TabCollection+SessionKey] and the SessionKey is taken from the url, so when you are close the browser you can be sure that there is no way to retrieve again the session for the simple reason that you will have to generate a new key for the user
hope that helped :)
Please mark as Answer, if it benefits you