Click here to Skip to main content
15,039,470 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Sir
I just want to know how to clear session variables on closed tab in ASP.NET.

I have trouble that I cannot kill session and log out when the user close the tab. I use the <body önunload="Clear()"> to check if the use close the website. It work great if I close the entire browser, but seem like it doesn't work well when closing tab. The state of login still effect when I open a new tab again and view it. I already tried in different browsers, but it stills same thing. So does anyone has solution ?
Thank u.
Updated 13-Sep-12 23:16pm
Azziet 14-Sep-12 5:11am
question is not too clear? closed tab in which context? although to clear session you can use Session.Abondon
bbirajdar 14-Sep-12 5:19am
Closed browser tab or AJAX Tabcontainer Tab ?
Shubham1389 14-Sep-12 5:22am
browser tab
bbirajdar 14-Sep-12 5:28am
Think again. If you implement this functionality, the user will not be allowed to close the tab, since it will log him out even if he does not want to log out. Once he knows he will be logged out after closing the tab, he will not open any link from the application in a new tab.

try this:
Session.RemoveAll(); // This Removes All session variables which is used on current application
bbirajdar 14-Sep-12 6:33am
He wants to clear session on close of browser tab. So in which event should he use this code?
prashant patil 4987 14-Sep-12 7:09am
// Clear all values from session state of 'Page'.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900