3
votes

I added an outputcache directive to my asp.net page (asp.net 4.0) as such:

        <%@ OutputCache Duration="3600" Location="Client" VaryByParam="None" %>

However, this does not appear to be working. When I check the http header information I see this:

        HTTP/1.1 200 OK => 
        Cache-Control => no-cache, no-store
        Pragma => no-cache
        Content-Type => text/html; charset=utf-8
        Expires => -1
        Server => Microsoft-IIS/7.0
        X-AspNet-Version => 4.0.30319
        Set-Cookie => ASP.NET_SessionId=0txhgxrykz5atrc3a42lurn1; path=/; HttpOnly
        X-Powered-By => ASP.NET
        Date => Tue, 15 Nov 2011 20:47:28 GMT
        Connection => close
        Content-Length => 17428

The above shows that the OutputCache directive was not applied. I even tried this from codebehind:

        this.Response.Cache.SetExpires(DateTime.Now.AddHours(1.0));
        TimeSpan ds = new TimeSpan(0, 1, 0, 0);
        this.Response.Cache.SetMaxAge(ds);

The above code should have the same results as the OutputCache directive, but when I check the http header information, I can see it's still not being applied.

Basically, the purpose here is to make sure that when a user clicks the back button and lands on my page, the page will not be retrieved from the server. I want to avoid getting the browser popup that asks the user to 'resend.' I want the browser to just use the copy of the page it has in it's cache.

Thanks in advace for any help.

1
That browser popup has nothing to do with cache... - Tomas Voracek

1 Answers

3
votes

From your question:

I want to avoid getting the browser popup that asks the user to 'resend.' I want the browser to just use the copy of the page it has in it's cache.

If browser asks you to resend data, it means that content was response to POST request.

According to RFC 2616 - Hypertext Transfer Protocol -- HTTP/1.1:

Some HTTP methods MUST cause a cache to invalidate an entity. This is either the entity referred to by the Request-URI, or by the Location
or Content-Location headers (if present). These methods are:

  • PUT
  • DELETE
  • POST

So, to make cache work, you need to convert your POST to GET.