Click here to Skip to main content
15,891,567 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,

I am using Asp.net vs2010 with c# language. I store the user login Id in Session for read the Value in some other Page it is working fine but now my need is clear the session variable after redirect to the login page.
I am using following Code for store the Variable.Any one help me how to do it.

Session["EmpId"] = txtUsername.Text;
Session["EmpPwd"] = txtPassword.Text;


Thanks advance!
Posted

1 solution

Write this code on the redirected page,
C#
Session["EmpId"] = null;
Session["EmpPwd"] = null;
//or
Session.Clear();
Session.Abandon();

Clear() - Removes all keys and values from the session-state collection.
Abandon() - Removes all the objects stored in a Session. If you do not call the Abandon method explicitly, the server removes these objects and destroys the session when the session times out.

-KR
 
Share this answer
 
v2
Comments
F-ES Sitecore 2-Oct-15 8:51am    
Rather than setting the variable to null you're better using Session.Remove()
Afzaal Ahmad Zeeshan 2-Oct-15 10:35am    
5ed; but as F-Es said, do not set them to null. Consider native functions to work with.

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