加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

为什么使用ASP.NET OutputCache继续返回200 OK,而不是304 Not Mo

发布时间:2020-12-16 03:46:56 所属栏目:asp.Net 来源:网络整理
导读:我有一个简单的aspx页面.这是它的顶部: – %@ Page Language="C#" AutoEventWireup="true" CodeFile="Foo.aspx.cs" Inherits="Foo" %%@ OutputCache Duration="3600" VaryByParam="none" Location="Any" % 现在,每当我点击FireFox中的页面时(无论是点击F5还
我有一个简单的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 Cache选项卡: –

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

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

Server是Win7上的localhost IIS7.5. (如响应数据中所列).

谁能看到我做错了什么?

解决方法

我认为你应该设置VaryByParam =“”而不是“none”以获得预期的304(当用户在url栏中使用enter键时不进行修改).

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读