RSS LOGORss   Welcome Guest  Login Register
Welcome to our Blogs
Back Back
Subject


mag
2008/07/08 01:49AM
How to Disable the user from using Back Button      Number of views: 2045

Hi, a nice trick I have found online on

http://www.codeguru.com/csharp/.net/net_debugging/debugging/article.php/c12891/

which the author gave a nice hint about disabling the user from clicking on the Back button, basically the Idea is,

First, Disable browser caching, then, adding a TimeStamp to the ViewState or SessionState objects in the ASP.NET.

Here is the code showing you how:

 

protected void Page_Load(object sender, EventArgs e)
   {
      Response.Cache.SetCacheability(HttpCacheability.NoCache);
      Response.Cache.SetExpires(Now.AddSeconds(-1));
      Response.Cache.SetNoStore();
      Response.AppendHeader("Pragma", "no-cache");

      if (Page.IsPostBack){
            if (isPageExpired()){
               Response.Redirect("expired.htm");
            }
            else {
               Session("TimeStamp") = Now.ToString;
               ViewState("TimeStamp") = Now.ToString;
            }
      }
      //...........
      //your own function here
   }

      private boolean isPageExpired()
      {
         if (Session("TimeStamp") == null ||
            ViewState("TimeStamp") == null)
            return false;
         else if (Session("TimeStamp") == ViewState("TimeStamp"))
            return true;
         else
            return false;
      }

 

best of luck,

 

Mohamed