0

I want to disable the broswer back button without using javascript. So far i have used this coding:

Response.CacheControl = "no-cache"
Response.CacheControl = "private"
Response.CacheControl = "public"

It's working fine in the internet explorer 8 but in case of mozilla fire fox it is not working.pls say same the solution to work in all browsers.

Thanks in advance

With Regards V.karthik

Nick Craver
  • 623,446
  • 136
  • 1,297
  • 1,155
Kajah User
  • 593
  • 5
  • 17
  • 56
  • I'm correcting the title so this doesn't get unnecessary down-votes, since the no-caching you're after is perfectly valid...just "disabling the back button" you'll find is frowned upon, for good reason :) But that's different from what you're after here. – Nick Craver May 29 '10 at 14:16

2 Answers2

0

Try

Response.Cache.SetCacheability(HttpCacheability.NoCache)
Ben Robinson
  • 21,601
  • 5
  • 62
  • 79
0

Check out the response in this question:

Best way to disable client caching

It's the same question, the same problem (IE working, FF not), and an accepted solution. I'm quoting:

Expires: Sun, 19 Nov 1978 05:00:00 GMT
Last-Modified: Fri, 12 Jun 2009 08:01:46 GMT (the actual modification date)
Cache-Control: store, no-cache, must-revalidate, post-check=0, pre-check=0

EDIT:

You can set the first two header like this in the codebehind of your page:

this.Response.Cache.SetExpires(DateTime.Now);
this.Response.Cache.SetLastModified(DateTime.Now);

But actually, it should be enough to do the following to deactivate caching (see also Whats the best way to deal with pages loaded via browser history in asp .net?):

this.Response.Cache.SetCacheability(HttpCacheability.NoCache);
this.Response.Cache.SetNoStore();

This generates the following headers:

Cache-Control: no-cache, no-store
Pragma: no-cache
Expires: -1
Community
  • 1
  • 1
marapet
  • 54,856
  • 12
  • 170
  • 184
  • where to use this coding same me in detail – Kajah User May 31 '10 at 05:32
  • how to use these coding and where to use – Kajah User May 31 '10 at 10:03
  • it is not working for mozila firefox3.6.3 and safari 4.0 pls help me to work in all browser.And Say codings where to use.i am struggling a lot.but it working fine in ie and google chrome. – Kajah User Jun 01 '10 at 06:52
  • You could use it in the Page_Load event handler for example. Please note that after a postback, you should redirect to an other page. See also http://blog.httpwatch.com/2008/10/15/two-important-differences-between-firefox-and-ie-caching/ – marapet Jun 01 '10 at 07:21
  • i have used this coding in the page load event it is working only in ie HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1)) HttpContext.Current.Response.Cache.SetValidUntilExpires(False) HttpContext.Current.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches) HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache) HttpContext.Current.Response.Cache.SetNoStore() in case of mozilla not working – Kajah User Jun 01 '10 at 07:39