posted 12/22/2008 6:11:08 AM by Vivek Thakur
The "Back" browser button (or for that matter any other browser button) cannot be actually disabled by a web application as the security context will not allow this (think of what nasty things could happen if web applications can remove buttons from client browsers!)
What we can do is to somehow make sure that browser does not cache the web pages (which will cause the"Back" "Forward" buttons to grey out), and this can be easily done by expiring the Response. The code for this has slightly changed in ASP.NET 2.0 (there is a new HttpCachePolicy class) :
/* * Code disables caching by browser. Hence hitting the back browser button * causes the Page_Load event to fire again. */ Response.Cache.SetCacheability(HttpCacheability.NoCache);Response.Cache.SetExpires(DateTime.Now); //or a date much earlier than current time
In ASP.NET 1.x the code was: Response.CacheControl = "no-cache"; Response.AddHeader("Pragma","no-cache"); Response.Expires = -1;
This will make the browser go to the server everytime the back button is clicked (for that particular page) and prevent any caching of the pages.
Vivek Thakur (Member since: 11/27/2008 11:54:25 AM) I am one of the administrators at CodeAsp.Net and I love programming, architecting solutions, code reviews, teaching and writing about ASP.NET.
View Vivek Thakur 's profile
try this in ur logout button/link..its works for me...as it refreshs the page after the Session.abondon(); so its not possible to go bak to ur previous page without logging again.. protected void logOut_b_Click(object sender, ImageClickEventArgs e) { Session.Abandon(); Response.AddHeader("Refresh",Convert.ToString((Session.Timeout * 0))); if(Session["Name"].ToString()=="") { Server.Transfer("login.aspx"); } }
protected void logOut_b_Click(object sender, ImageClickEventArgs e) { Session.Abandon(); Response.AddHeader("Refresh",Convert.ToString((Session.Timeout * 0))); if(Session["Name"].ToString()=="") { Server.Transfer("login.aspx"); } }
Leave a comment
It's fast, easy and free! Submit articles, get your own blog, ask questions & give answers in the forums, and become a better developer, faster.
enter your email address: