Click here to Skip to main content
15,900,378 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi there,
I am developing an ASP.NET website, I have a data entry page which i can only access using a login control.
My problem is, when I navigate away from my data entry page using the 'Back' button of my browser or by clicking on logout, I am redirected to the previous page or my desired page, which is good, but if I click on the 'Forward' button of my browser, I am redirected to my data entry page without being prompted for any login information.

What I want is any time I try to access my data entry page, especially when using the browser navigation buttons, I want to be redirected to login page first so that I can enter in my login credentials.

Thanks in advance,
Yours faithfully
Martin
Posted
Updated 17-Jul-10 7:03am
v2

This happens because of cache.

If it suits you, one way to handle it can be:
1. clear the sessions
2. clear the cache such that browser has no history (this will make back/forward button in browser grayed out disabled.)

code for clearing cache can be put up in code behind as follows:
C#
// Code disables caching by browser. Hence the back browser button
// grayed out and could not causes the Page_Load event to fire 
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1));
Response.Cache.SetNoStore();


You can add somethin similar in form aspx if you want to place it there:
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="0"></meta></meta></meta>


Similarly:
You can clear browser history through JavaScript or Codebehind....

JavaScript
//clears browser history and redirects url
<SCRIPT LANGUAGE=javascript> {  var Backlen=history.length;   history.go(-Backlen);   window.location.href=page url }</SCRIPT>


OR
C#
Page.ClientScript.RegisterStartupScript(this.GetType(),"cle","windows.history.clear",true);


OR as you say in you logout event:
C#
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>");   
}


Just Google it if you face issues!
 
Share this answer
 
v2
clear the session and cookies..

and also you don't need to worry as if you destroy cookies and session even if the browser cache redirects you to that page, you ll have to login for the page to perform any operation.
 
Share this answer
 
I'm sure you are not using IE. So do not worry, the user can only see the page but when (s)he do a postback or further navigation, they will be redirect back to home until they log in. The page you are seeing is cached page not real from server.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900