gpt4 book ai didi

asp.net - 为什么使用 ASP.NET OutputCache 不断返回 200 OK,而不是 304 Not Modified?

转载 作者:行者123 更新时间:2023-12-02 06:16:24 25 4
gpt4 key购买 nike

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

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

现在,每次我在 FireFox 中点击页面(按 F5 或在网址栏中按 Enter)时,我都会收到 200 OK 响应。以下是 FireBug 的回复示例:-

请求 header :-

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

响应 header :-

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 回复。

请求 header :-

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

响应 header :-

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上的本地主机IIS7.5。 (如响应数据中所列)。

有人能看出我做错了什么吗?

最佳答案

我认为你应该设置VaryByParam=""而不是"none"以获得预期的304(当用户使用网址栏中的回车键)。

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

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

关于asp.net - 为什么使用 ASP.NET OutputCache 不断返回 200 OK,而不是 304 Not Modified?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2948079/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com