1

I have Asp.net MVC page/view is always fetched from cache when using browser back button. This issue is with safari browser alone and works properly in other browser such as Chrome,Firefox and IE. I went through so many posts which describes similar issues. But till now I am not able find a solution for this .

This is below code from my action method

[OutputCache(Duration = 0, Location = OutputCacheLocation.Any, VaryByParam = "*")]
 public ActionResult ABC(string taxonomy)
 {
    return View()
 }

In safari response shows the below

Cache-Control:public, max-age=0, s-maxage=0
Connection:Close
Content-Length:15849
Content-Type:text/html; charset=utf-8
Date:Wed, 12 Nov 2014 06:07:55 GMT
Expires:Wed, 12 Nov 2014 06:07:52 GMT
Last-Modified:Wed, 12 Nov 2014 06:07:52 GMT
Server:ASP.NET Development Server/10.0.0.0
Vary:*
X-AspNet-Version:4.0.30319
X-AspNetMvc-Version:4.0

I have also tried added the bleow code to the action method

[OutputCache(Duration = 0, Location = OutputCacheLocation.Any, VaryByParam = "*")]
public ActionResult ABC(string taxonomy)
{
HttpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Response.AppendHeader("Cache-Control", "private, no-cache, no-store, must-revalidate, max-age=0, proxy-revalidate, s-maxage=0"); // HTTP 1.1.
HttpContext.Response.AppendHeader("Pragma", "no-cache"); // HTTP 1.0.
HttpContext.Response.AppendHeader("Expires", "0"); // Proxies.
HttpContext.Response.AppendHeader("Vary", "*");
}

So the response was like below

Cache-Control:no-cache
Connection:Close
Content-Length:15849
Content-Type:text/html; charset=utf-8
Date:Wed, 12 Nov 2014 06:20:58 GMT
Expires:-1
Pragma:no-cache, no-cache
Server:ASP.NET Development Server/10.0.0.0
X-AspNet-Version:4.0.30319
X-AspNetMvc-Version:4.0

But what ever i do the the safari get's the page from cache when i use the back button of the browser. Kindly help with solution /suggestion to solve this problem .

Midhun Murali
  • 2,089
  • 6
  • 28
  • 49

2 Answers2

0

I had similar problem with Safari and adding onunload="" in body tag and I solved it. Check: Preventing cache on back-button in Safari 5

Community
  • 1
  • 1
Jerry
  • 1
0

I found this alternative approach which solved my problem . Hope this help everyone facing similar issues How do you disable back and forward caching on iOS Safari?

Community
  • 1
  • 1
Midhun Murali
  • 2,089
  • 6
  • 28
  • 49