【问题标题】:Why does using ASP.NET OutputCache keep returning a 200 OK, not a 304 Not Modified?为什么使用 ASP.NET OutputCache 不断返回 200 OK,而不是 304 Not Modified?
【发布时间】:2010-06-01 08:00:28
【问题描述】:

我有一个简单的 aspx 页面。这是它的顶部:-

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

现在,每次我在 FireFox 中点击页面(点击 F5 或在 url 栏中点击 enter)我都会收到 200 OK 响应。这是来自 FireBug 的示例回复:-

请求标头:-

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

响应标头:-

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 缓存选项卡:-

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

现在,如果我使用请求生成器在 Fiddler 中尝试(并且没有额外数据),我也会不断收到相同的 200 OK 回复。

请求标头:-

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

响应标头:-

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

看起来它要求缓存它,但它不是:(

服务器是 Win7 上的 localhost IIS7.5。 (如响应数据中所列)。

谁能看出我做错了什么?

【问题讨论】:

  • 这可能是 URL 重写的原因。尝试通过~.aspx路径访问页面,如果没问题,那么原因是urlRewriter模块。
  • @Pure.Krome 有没有为此找到解释/解决方案?
  • @GabyakaG.Petrioli 不。从来没有得到这个答案。

标签: asp.net iis-7 outputcache cache-control iis-7.5


【解决方案1】:

我认为您应该设置VaryByParam="" 而不是"none" 以获得expected 304(当用户在网址栏中使用回车键时未修改)。

使用"" Vary HttpHeader不会作为请求标头的一部分发送到服务器。

使用"None" Vary HttpHeader作为请求标头的一部分发送到服务器。

【讨论】:

    【解决方案2】:

    尝试从另一台机器上运行网站,以确保这不是 localhost 调用的行为。

    【讨论】:

    • 还是一样。全部 200 个。
    猜你喜欢
    • 1970-01-01
    • 2010-09-25
    • 2016-02-10
    • 1970-01-01
    • 1970-01-01
    • 2017-12-01
    • 2014-11-11
    • 2021-06-18
    • 2018-10-08
    相关资源
    最近更新 更多