Click here to Skip to main content
16,021,125 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
i want to clear a session when the session page is closed or redirect to an another page
Posted
Comments
raneshtiwari 11-Dec-13 5:21am    
Session can clear from server side only, so have to know when your webpage will close and when it's redirect to another page, If you already know then assign null in session variable e.g.
Session["yoursessionname"]=null;

1 solution

Hi !!
Hope this Helps
C#
if(!IsPostBack)
       {
           if (Session["LoginId"] == null)
               Response.Redirect("frmLogin.aspx");
           else
           {
               Response.ClearHeaders();
               Response.AddHeader("Cache-Control", "no-cache, no-store, max-age=0, must-revalidate");
               Response.AddHeader("Pragma", "no-cache");
                           }
       }


You can clear the User Session by:
C#
Session.Clear();
Session.Abandon();
System.Web.Security.FormsAuthentication.SignOut();
 
Share this answer
 

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