Wednesday, November 16, 2011

Prevent back button after logout.....clear cache..in C#


In Masterpage.cs


protected void lnkSignout_Click(object sender, EventArgs e)
    {
        FormsAuthentication.SignOut();
        Session.Clear();
        Session.RemoveAll();
        Session["User_Details"] = null;
        string[] myCookies = Request.Cookies.AllKeys; foreach (string cookie in myCookies) { Response.Cookies[cookie].Expires = DateTime.Now.AddDays(-1); }
        Session.Abandon();
        Page.ClientScript.RegisterStartupScript(GetType(), "Javascript", "javascript: closeWindow(); ", true);

        FormsAuthentication.RedirectToLoginPage();
               
    }

    protected void Page_Init(object Sender, EventArgs e)
    {

        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1));
        Response.Cache.SetNoStore();

    }

No comments:

Post a Comment