Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does using ASP.NET OutputCache keep returning a 200 OK, not a 304 Not Modified?

i have a simple aspx page. Here's the top of it:-

<%@ Page 
    Language="C#" 
    AutoEventWireup="true" 
    CodeFile="Foo.aspx.cs" 
    Inherits="Foo" %>
<%@ OutputCache Duration="3600" VaryByParam="none" Location="Any" %>

Now, every time I hit the page in FireFox (either hit F5 or hit enter in the url bar) I keep getting a 200 OK response. Here's a sample reply from FireBug :-

Request Headers:-

GET /sitemap.xml HTTP/1.1
Host: localhost.foo.com.au
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2) 
            Gecko/20100115 Firefox/3.6
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-au,en-gb;q=0.7,en;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Cookie: <snipped>
If-Modified-Since: Tue, 01 Jun 2010 07:35:17 GMT
If-None-Match: ""
Cache-Control: max-age=0

Response Headers:-

HTTP/1.1 200 OK
Cache-Control: public
Content-Type: text/xml; charset=utf-8
Expires: Tue, 01 Jun 2010 08:35:17 GMT
Last-Modified: Tue, 01 Jun 2010 07:35:17 GMT
Etag: ""
Server: Microsoft-IIS/7.5
X-Powered-By: UrlRewriter.NET 2.0.0
X-AspNet-Version: 4.0.30319
Date: Tue, 01 Jun 2010 07:35:20 GMT
Content-Length: 775

Firebug Cache tab:-

Last Modified   Tue Jun 01 2010 17:35:20 GMT+1000 (AUS Eastern Standard Time)
Last Fetched    Tue Jun 01 2010 17:35:20 GMT+1000 (AUS Eastern Standard Time)
Expires Tue Jun 01 2010 18:35:17 GMT+1000 (AUS Eastern Standard Time)
Data Size   775
Fetch Count 105
Device  disk

Now, if i try it in Fiddler using the Request Builder (and no extra data) I also keep getting the same 200 OK reply.

Request Headers:-

GET http://localhost.foo.com.au/sitemap.xml HTTP/1.1
User-Agent: Fiddler
Host: foo.com.au

Response Headers:-

HTTP/1.1 200 OK
Cache-Control: public
Content-Type: text/xml; charset=utf-8
Expires: Tue, 01 Jun 2010 07:58:00 GMT
Last-Modified: Tue, 01 Jun 2010 06:58:00 GMT
ETag: ""
Server: Microsoft-IIS/7.5
X-Powered-By: UrlRewriter.NET 2.0.0
X-AspNet-Version: 4.0.30319
Date: Tue, 01 Jun 2010 06:59:16 GMT
Content-Length: 775

It looks like it's asking to cache it but it's not :(

Server is a localhost IIS7.5 on Win7. (as listed in the Response data).

Can anyone see what I'm doing wrong?

like image 287
Pure.Krome Avatar asked Jun 01 '10 08:06

Pure.Krome


1 Answers

I think you should set VaryByParam="" instead "none" in order to get the expected 304 (not modified when the user use enter key in url bar).

Using "" Vary HttpHeader is not sent to the server as part of the request headers.

Using "None" Vary HttpHeader is sent to the server as part of the request headers.

like image 93
Jose3d Avatar answered Nov 15 '22 09:11

Jose3d