Click here to Skip to main content
15,662,754 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I have a web application project and i have a logout in treeview and i need to clear all the session variables when logout node is clicked. I used Session.Abandon() and Session.Clear() but it didnt work for me. Can anyone help me? Thanks in advance.
Prerak Patel 10-Nov-11 1:25am    
'it didnt work for me' is not enough. Elaborate. Share some code if required.
skkworld 10-Nov-11 1:39am    
In the logout.aspx.cs page i used the following code:
protected String m_TargetPageTxt = "";
protected void Page_Load(object sender, EventArgs e)
m_TargetPageTxt = "Login.aspx";

and I used the JS in logout.aspx source as

<script language="javascript">
var TargetPageTxt = '<%=m_TargetPageTxt%>';
if (TargetPageTxt != "") {;

It goes to the login page when i click logout but the session variables are not cleared in all the pages.

Session.Abandon() and Session.Clear() are different methods.
session.clear() will clear session value not remove the session from memeory. where .Abandon() is removes all session from memory.

may be your session.abandon worked but session not refreshed, try the following

IE settings Toos Menu --> Internet options --> Setting (under browser history) --> select "Everytime i visit to the page" --> close the browser and try again
Share this answer
skkworld 10-Nov-11 2:29am    
Hey thanks 4 ur help.
It had worked.
Thanks a lot once again.
member60 10-Nov-11 2:37am    
Morgs Morgan 10-Nov-11 7:26am    
Just remember that you will never always sit on each client computer to manually clear their browser history. I would suggest a way to achieve this programmatically, not manually.
How about setting your session variables to null?
like so:
Session[ "id" ] = null;
Session[ "password" ] = null;

if(Session[ "id" ] != null && Session[ "password" ] != null)
   //user is logged in
   //user is not logged in

Happy coding,
Share this answer
Try this
At logout
Session["sessionname"]= "";
Share this answer
skkworld 10-Nov-11 1:43am    
I did that but it didnt work

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