简体   繁体   中英

iPhone not caching Asp.Net pages

If I create a basic asp.net application and set the @outputcache the page is cached fine in chrome & IE on the desktop. First request returns 200, subsequent request return 304 for the default.aspx. (I'm monitoring through fiddler)

However accessing the same page from an iPhone I noticed that it's always returning 200 for the aspx file. All resources are being caching and are returning 304's. So it's just the aspx page.

Any ideas why this is happening?

Some technical details:

  • <%@ OutputCache Duration="30" VaryByParam="None" Location="Any" %>
  • Stock standard ASPX page. Content-Length: 2464
  • Reloading on the iPhone using refresh control or keyboard "go" doesn't make a difference.
  • Explicitly setting eTag does not make a difference
  • Last-Modified is set
  • but If-Modified-Since is not being send for the ASPX page
  • Latest IOS 4.3.1
  • IIS 7.5 running on Win7 using ASP.NET 4

I think I figured it out. Feel free to correct me however. Website caching is a very messy area.

The root of the problem is that the iPhone is not sending "If-Modified-Since" headers with it's requests. Without that the server cannot reply with a 304.

After some experiments I've found that if you use a link to navigate to the page it will send the 'If-Modified-Since' header and everything works as expected and the server neatly returns a 304.

Cases where it does not send a "If-Modified-Since" even though it's cached:

  • Typing in the URL
  • Pressing the refresh button
  • Selecting the URL and pressing Go
  • Opening as a bookmark
  • Opening from a saved reference on the home screen

It only seems to be doing this for the primary url everything else that is referenced does have a "If-Modified-Since" header (where applicable).

Note: I've tested this on IOS 4.3.1 only. Looking at the link Paddo send and further investigation into that area it seems that Apple likes to change caching behaviour between IOS versions.

Found this, re php (will also apply to .net)... iphone doesn't seem to cache any resource over 15k in size, and total cache size is 1.5MB. Note this is old information so may have changed.

http://www.phpied.com/iphone-caching/

The solution for a file over 15k, is to use an offline application cache manifest file, as outlined here: http://developer.apple.com/library/safari/#documentation/AppleApplications/Reference/SafariWebContent/Client-SideStorage/Client-SideStorage.html

PS I know your content length is below 15k - so something else must be amiss... but I'm still hopeful that the manifest file will work.

for ASP.NET just use

Response.AddHeader( "Cache-Control","no-cache");

or

Response.AddHeader( "Pragma", "no-cache");

or

Response.Cache.SetCacheability(HttpCacheability.NoCache);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM