title: Disabling backbutton of browser in C#
body: <pre><code>&lt;script type="text/javascript"&gt;
      {
          function DisableBackButton() {
              window.history.forward()
          }
  
          DisableBackButton();
  
          window.onload = DisableBackButton;
          window.onpageshow = function (evt) { if (evt.persisted) DisableBackButton() }
          window.onunload = function () { void (0) }
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>I am using the following code in the master page to diable the back button.</p>
  
  <pre><code>Response.Cache.SetCacheability(HttpCacheability.NoCache);
  Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1));
  Response.Cache.SetNoStore();
  
  Response.ExpiresAbsolute = DateTime.Now.AddDays(-1d);
  Response.Expires = -1500;
  Response.CacheControl = "no-cache";
  Page.Response.Cache.SetCacheability(HttpCacheability.NoCache);
  </code></pre>
  
  <p>I have a master page in that logout button is there once user click on that user will be redirected to logout page. This is working fine and once I am clicking on back button it is taking me to the last page I browsed. Even I tried with JavaScript.    </p>
  
  <p>I am creating timing out the session after 5 minutes. When session expires user will be redirected to session expiry page there also backbutton is taking me to the last page browsed.</p>