I am working on a ASP.NET application. I want to prevent the user from viewing the previous page using the back button in the browser after logging out from the application开发者_如何转开发.
Thank You for all your replies.
Code:
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1));
Response.Cache.SetNoStore();
Response.AppendHeader("Pragma", "no-cache");
i have used this code in page load event. Its working fine.
here is solution how to do that, but note that user can remember and write the url of the page you don't wont him to see after logout,so you should implement authentication mechanism
Why do you want to prevent the back button from working. Do avoid things that hinder the normal action of a user with the browser.
Instead you can check for Session availability in the page. If Session is not available then redirect the user to another page.
Anyways here is an article on this subject.
A Thorough Examination of "Disabling the Back Button."
I agree with phoenix... But one thing is the page would get already displayed when back button fires, from the cache and hence you can check for session validity only during postback... and remember, isPostBack will be true in that scenario.
You can use the following code to set the page expiry. This if included in a page, will display a page expired message when the user hits back button after going out of the page. But beware, he can always hit refresh and can perform the post back again.
Caution : using it in every other page, will frustrate the application users...
Response.AppendHeader("Pragma", "no-cache");
Response.AppendHeader("Cache-Control", "no-cache");
Response.CacheControl = "no-cache";
Response.Expires = -1;
Response.ExpiresAbsolute = new DateTime(1900, 1, 1);
Response.Cache.SetCacheability(HttpCacheability.NoCache);
精彩评论