Monday, July 28, 2008

How To Clear Browser Session In Asp.net

In this post i will show how to clear Browser history in asp.net.just write down following code in Logout button.
protected void LogOut()
   {
       Session.Abandon();
       string nextpage = "Logoutt.aspx";
       Response.Write("<script language=javascript>");

       Response.Write("{");
       Response.Write(" var Backlen=history.length;");

       Response.Write(" history.go(-Backlen);");
       Response.Write(" window.location.href='" + nextpage + "'; ");

       Response.Write("}");
       Response.Write("</script>");

   }

6 comments:

  1. this code not working

    send other code in my mail id

    ReplyDelete
  2. @Pankaj : can i have your email address?

    ReplyDelete
  3. this is not working properly...can u send it to my mail my mail id is, kumarvinit86@gmail.com

    ReplyDelete
  4. Hi,
    This code is working but when we click on the forward button it is moving to the previous page

    ReplyDelete
  5. This code is not working.

    ReplyDelete
  6. Not working...my requirement is i hav one form with 2 textboxes...afetr submitting the values..the browser needs to be get cleared.. means the values i enetred already should not appear when i click the control to enter 2nd record..

    ReplyDelete