Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent browser back button after logout? [duplicate]

Tags:

jquery

c#

asp.net

How can i stop the back button after user has logout ? (LOGOUT button is in master page) Using webforms

I have few pages, the last page is the final page and after log out when i click back button its showing the previous page.How do i avoid this.Pls help me with the code

Code needs to trigger only after LOGOUT .The user must be able to go back n see previous page if he has to make any changes while he's loged in.

like image 273
Challa Jyothi Avatar asked Feb 21 '14 09:02

Challa Jyothi


2 Answers

You should set the correct HTML headers. According to this these are the ones that work on all browsers:

Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
Expires: 0

You can set them like this:

HttpContext.Current.Response.AddHeader("Cache-Control", "no-cache, no-store, must-revalidate");
HttpContext.Current.Response.AddHeader("Pragma", "no-cache");
HttpContext.Current.Response.AddHeader("Expires", "0");
like image 160
Patrick Hofman Avatar answered Oct 29 '22 07:10

Patrick Hofman


<script>
  function preventBack(){window.history.forward();}
  setTimeout("preventBack()", 0);
  window.onunload=function(){null};
</script>

it may work for you

like image 41
Chirag Sutariya Avatar answered Oct 29 '22 07:10

Chirag Sutariya