views:

1318

answers:

5

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.

A: 

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."

rahul
There is a more fundamental problem than this - using the back button doesn't necessarily result in a visit to the server (often doesn't) the browser will display a locally cached version of the page. This is why the back button is, generally, a pain for developers. There are, I suspect, things that could be done (you may be able to manipulate the history for exampe) but generally speaking this attempting to deal with something beyond one's easy control (unless I'm missing something...)
Murph
A: 

put this code in the page, where you want to prevent.

HttpContext.Current.Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);

Plus you need to put extra check for your user session

Muhammad Akhtar
A: 

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

ArsenMkrt
A: 

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);
The King
+1  A: 

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.

Geetha