Click here to Skip to main content
15,036,051 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi,
This is Kiran. I have one doubt in ASP.NET. I use sessions in my project but I need to know how to clear the sessions when window is closed.
Posted
Updated 18-Aug-10 21:15pm
v2

Kiran

As a default, Sessions gets cleared once the window is closed.

However, if you need to clear the variables manually, use the function "session_onEnd" in global.asax

Regards
   
You can write the code in javascript,

JavaScript
window.onunload = function ()
{
 document.getElementById(<%btnHiddenSession.ClientID%>).click();
}


and in codebehind

C#
public void btnHiddenSession_Click(object sender, EventArgs e)
{
Session.Abandon();
}
   
Kiran,

Use
Session.Abandon()
method to clear all ur sessions.

This may help you.

Regards,
SureshKumar
   
Hi,
Kiran,
If you clear all session when window close you will just write(this code used for only one session)

if( Session["Your Session Name"] != null)
{
Session["Your Session Name"] = null;
}
or
Write(this is for all session) Session.Abandon().


thanks
   

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