5

after upgrade to iOS6.0 release, ajax login page stopped working. It looks like ajax post request made by jquery $.ajax is cached in safari even after adding random querystring parameter and set Cache-control to "no-cache" (these found on net as solution for cache problem). First login attempt works fine, but after logout at second login request browser don't get any response body from server. only headers.

The same is working in IOS 6 GM and 5 versions and in all desktop browsers.

Any Ideas?

Boris
  • 119
  • 2
  • 11

2 Answers2

5

i just read this article at ars technica that seem to be related to your problem. It seems to be an Apple "over optimization" of Safari in iOS6.

dweeves
  • 5,525
  • 22
  • 28
  • I too read many posts about this issue, and tried two solutions I found: no-cache header and random parameter. It not worked for me, Now I try to move all POST AJAX requests to GET requests. But I not sure that it is safe solution. Is it safe to send password in GET even in SSL session? – Boris Sep 24 '12 at 14:02
  • random param should be sufficient alone i think since it will generate a new url per request. – dweeves Sep 24 '12 at 14:03
  • worked with asp.net only after adding pragma:no-cache header in IIS Cache-Control: no-cache was not enought – Boris Sep 25 '12 at 21:32
  • I would not recommend sending sensitive data using GET. Use post or put. I experienced the issue with safari caching my post requests. The no-cache header is now added by the server and it works fine now. Can you post a screenshot of your request and response headers for a post that seems to be cached? – Guillaume Schuermans Jan 20 '13 at 22:43
  • Sorry, missed your comment above :) good to read you too have it fixed. Safari 6 caused me some issues already. – Guillaume Schuermans Jan 20 '13 at 22:45
1

This topic is also covered in a lot of detail here: Is Safari on iOS 6 caching $.ajax results?

One additional note, however, not covered in the above.

There was a useful comment re WCF that is also applicable to ASP.NET MVC applications re SetCacheability. I recommend that these calls be limited to non-GET requests, to avoid losing the benefit of cache on GETs.

I use a Controller base class that all of my controllers inherit from for a number of reasons, and this served well in that my Initialize override can handle setting my caching headers.

public class SmartController : Controller
{
    ...
    public HttpContextBase Context { get; set; }

    protected override void Initialize(System.Web.Routing.RequestContext requestContext)
    {
        Context = requestContext.HttpContext;

        if (Context.Request.RequestType != "GET")
        {
            Context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
        }

        base.Initialize(requestContext);
        ...
    }
...
}
Community
  • 1
  • 1
Jim Speaker
  • 1,303
  • 10
  • 28