Clear Session While Browser Close
-
-
Hi All, How to clear session when i close the browser. I have assigned the following value in session Session["SessionId"] = sessionId; Session["userId"] = userId; I want to clear this value while user close Browser Thanks and regards, Amit Patel
Why do you require an extra server call to clear session.. Rather you can use Session Timeout easily which is automatically called.
Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Windows7 API Code Pack
Simplify Code Using NDepend
Basics of Bing Search API using .NET -
Hi All, How to clear session when i close the browser. I have assigned the following value in session Session["SessionId"] = sessionId; Session["userId"] = userId; I want to clear this value while user close Browser Thanks and regards, Amit Patel
For that you have to capture the browser close event from javascript and if it is browser close then open a new page remove the session from server side of that page then close that page.I have impleneted in this way.The sample code is : Javscript code to capture the browser close event and accordingly open the new page to remove the session
function CloseSession() {
, Alt+F4 , File -> Close
if(window.event.clientX < 0 && window.event.clientY <0)
{
window.open("CloseSession.aspx", "OpenWindow_Close_Session",'left=12000,top=1200,width=10,height=1');
}
}Call this method on unload of your master Body . onunload="DeleteUserLog()" Now in CloseSession.aspx pages, you can do what ever you want and register the client script to close it automatically after doing the task. Hope it'll help you. :)
Cheers!! Brij
-
Hi All, How to clear session when i close the browser. I have assigned the following value in session Session["SessionId"] = sessionId; Session["userId"] = userId; I want to clear this value while user close Browser Thanks and regards, Amit Patel
Session.clear
-
Why do you require an extra server call to clear session.. Rather you can use Session Timeout easily which is automatically called.
Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Windows7 API Code Pack
Simplify Code Using NDepend
Basics of Bing Search API using .NETHi I want to implement functionality where user can login from one system only if he logs in from other machine then he should logged out from another machine so for this we implemented forced logout for this i created on dictionary in App code in global which contains user id and corrospoding session id but when i closing my browser it is not getting removed so when i m logging from same machine it is also iving forced logout is session is not expired so i dont want to show this message Thanks amit
-
Hi All, How to clear session when i close the browser. I have assigned the following value in session Session["SessionId"] = sessionId; Session["userId"] = userId; I want to clear this value while user close Browser Thanks and regards, Amit Patel