12Aug/090
Disable users goto previous pages
Due to security reasons or some other reasons, we don’t want the users have the ability to go back to previous pages (by clicking the Back button in the browser). It is impossible to disable the Back button directly, thus we have to do something in the code.
There are at least two ways of disabling the users to goto previous pages. One is using JavaScript in the client side, another one is to set the pages that have already expired in the server-side.
In the client side:
<script type="text/javascript">
function noBack(){
window.history.forward();
}
noBack();
window.onload = noBack;
window.onpageshow = function(evt) { if (evt.persisted) noBack(); }
</script>
In the server side:
protected void Page_Init(object sender, EventArgs e)
{
Response.Cache.SetExpires(DateTime.Now.AddDays(-1));
Response.Cache.SetCacheability(HttpCacheability.NoCache);
}
The way of using JavaScript in the client side has a drawback. This cannot really forbid the users go back to previous pages when the JavaScript function is disabled in the browser side.