缓存功能不会产生预期的结果(错误?) [英] Cache feature doesn't produce expected result (bug?)

查看:62
本文介绍了缓存功能不会产生预期的结果(错误?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我认为这个问题需要深入了解浏览器

缓存的工作原理。我希望我能在这里找到专家。


我可能在asp.net文档中发现了一个怪癖或者我不明白

是什么SetAllowResponseInBrowserHistory确实。

在研究缓存时,我尝试了以下页面中的代码示例:

http://msdn2.microsoft.com/library/9...us,vs.80).aspx


我觉得这段代码很荒谬,因为它试图表明你可以通过浏览器的历史记录功能查看

已经_posted_的页面。 br />

你能试试这个代码并报告你的发现吗?我在一个干净的

文档说你会看到旧的页面浏览器。


我做了一些测试,这是以下代码对响应的处理

标题:


Response.Cache.SetCacheability(HttpCacheability.No Cache)

Response.Cache.SetAllowResponseInBrowserHistory(Fa lse)''False

是默认值

''缓存控制:无缓存

''到期:-1

''Pragma:no - 缓存


Response.Cache.SetCacheability(HttpCacheability.No Cache)

Response.Cache.SetAllowResponseInBrowserHistory(Tr ue)

''缓存控制:无缓存

''Pragma:no - 缓存

关于Expires标题的文档是正确的。当SetAllowResponseInBrowserHistory

= True时,Expires标题消失。


是否有人知道为什么调用SetAllowResponseInBrowserHistory

存在且哪里有它可能有用吗?


谢谢,

Tom Pester

Hi,

I think this question requires an in depth understanding of how a browser
cache works. I hope I can reach an expert here.

I may have found a quirk in the asp.net documentation or I don''t understand
what the SetAllowResponseInBrowserHistory does.
While researching caching I tried the code sample at the following page :

http://msdn2.microsoft.com/library/9...us,vs.80).aspx

I find this code absurd since it tries to show that you can view a page that
has been _posted_ with the history feature of the browser.

Can you try this code and report your findings please? I tried it on a clean
VM install and on my dev pc: the browser says "page expired".
The docs say you would see the old page in the browser.

I did some tests and this is what the following code does with the response
headers :

Response.Cache.SetCacheability(HttpCacheability.No Cache)
Response.Cache.SetAllowResponseInBrowserHistory(Fa lse) '' False
is the default
''Cache-Control: no-cache
''Expires: -1
''Pragma: no - Cache

Response.Cache.SetCacheability(HttpCacheability.No Cache)
Response.Cache.SetAllowResponseInBrowserHistory(Tr ue)
''Cache-Control: no-cache
''Pragma: no - Cache
The docs are right about the Expires header. When SetAllowResponseInBrowserHistory
= True the Expires header disappears.

Does anybody have a clue why SetAllowResponseInBrowserHistory was called
into existence and where it might be useful?

Thanks,
Tom Pester

推荐答案

re:
有没有人知道为什么SetAllowResponseInBrowserHistory被调用存在
以及它可能有用的地方?


SetAllowResponseInBrowserHistory(false)是默认值。


你只需要设置HttpCachePolicy.SetAllowResponseInBrowserHistory

当你需要将其设置为true以覆盖NoCache设置


Juan T. Llibre

ASP.NET MVP
http://asp.net.do/foros/

Foros de ASP.NET en Espa?ol

Ven,y hablemos de ASP.NET ...

============== ========


<到******************** @ pandora.be>在留言中写道

新闻:a1 ************************** @ news.microsoft.c om ...

我认为这个问题需要深入了解浏览器缓存的工作原理。我希望我能在这里找到专家。

我可能在asp.net文档中找到了一个怪癖,或者我不明白
SetAllowResponseInBrowserHistory的作用。<在研究缓存时,我尝试了以下页面中的代码示例:

http://msdn2.microsoft.com/library/9...us,vs.80).aspx
我觉得这段代码很荒谬,因为它试图表明你可以用浏览器的历史记录功能查看已经
_posted_的页面。

你能试试这段代码并报告你的发现吗请?我在一个干净的虚拟机安装上尝试了它并在我的开发者电脑上:浏览器说页面已过期。
文档说你会在浏览器中看到旧页面。

Response.Cache.SetCacheability(HttpCacheability.No Cache)
Response.Cache.SetAllowResponseInBrowserHistory(Fa lse )''错误是默认的
''缓存控制:无缓存
''到期:-1
''Pragma:no - 缓存

响应.Cache.SetCacheability(HttpCacheability.No Cache)
Response.Cache.SetAllowResponseInBrowserHistory(Tr ue)
''Cache-Control:no-cache
''Pragma:no - Cache

关于Expires标题的文档是正确的。当SetAllowResponseInBrowserHistory =
真的Expires标题消失。

有没有人知道为什么SetAllowResponseInBrowserHistory被调用存在
它可能有用吗?
谢谢,
Tom Pester
Does anybody have a clue why SetAllowResponseInBrowserHistory was called into existence
and where it might be useful?
SetAllowResponseInBrowserHistory(false) is the default.

You only need to set HttpCachePolicy.SetAllowResponseInBrowserHistory
when you need to set it to true to override the NoCache setting


Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Espa?ol
Ven, y hablemos de ASP.NET...
======================

<To********************@pandora.be> wrote in message
news:a1**************************@news.microsoft.c om... Hi,

I think this question requires an in depth understanding of how a browser cache works. I
hope I can reach an expert here.

I may have found a quirk in the asp.net documentation or I don''t understand what the
SetAllowResponseInBrowserHistory does.
While researching caching I tried the code sample at the following page :

http://msdn2.microsoft.com/library/9...us,vs.80).aspx

I find this code absurd since it tries to show that you can view a page that has been
_posted_ with the history feature of the browser.

Can you try this code and report your findings please? I tried it on a clean VM install
and on my dev pc: the browser says "page expired".
The docs say you would see the old page in the browser.

I did some tests and this is what the following code does with the response headers :

Response.Cache.SetCacheability(HttpCacheability.No Cache)
Response.Cache.SetAllowResponseInBrowserHistory(Fa lse) '' False is the default
''Cache-Control: no-cache
''Expires: -1
''Pragma: no - Cache

Response.Cache.SetCacheability(HttpCacheability.No Cache)
Response.Cache.SetAllowResponseInBrowserHistory(Tr ue)
''Cache-Control: no-cache
''Pragma: no - Cache
The docs are right about the Expires header. When SetAllowResponseInBrowserHistory =
True the Expires header disappears.

Does anybody have a clue why SetAllowResponseInBrowserHistory was called into existence
and where it might be useful?

Thanks,
Tom Pester



嗨Juan,


谢谢你响应。
Hi Juan,

Thanks for your response.
当你需要将它设置为true以覆盖NoCache设置时,你只需要设置HttpCachePolicy.SetAllowResponseInBrowserHistory
You only need to set HttpCachePolicy.SetAllowResponseInBrowserHistory
when you need to set it to true to override the NoCache setting



将SetAllowResponseInBrowserHistory设置为True不会触及/覆盖

no-cache值。它只删除expires = -1标题。


此代码显示:

Response.Cache.SetCacheability(HttpCacheability.No Cache)

Response.Cache.SetAllowResponseInBrowserHistory(Tr ue)


服务器发送以下缓存相关标头:

''缓存控制:否 - 缓存

''Pragma:不 - 缓存


我不知道你是否对http标题及其行为有经验但是

你可以测试一下这个页面上的代码并报告你的结果吗? :

http://msdn2.microsoft.com/library/9...us,vs.80).aspx


如果您运行示例并返回浏览器我想你会发现

页面上的文字是错误的。


先谢谢你,Tom



Setting SetAllowResponseInBrowserHistory to True doesn''t touch/override the
"no-cache" value. It only removes the expires=-1 header.

This code shows this :
Response.Cache.SetCacheability(HttpCacheability.No Cache)
Response.Cache.SetAllowResponseInBrowserHistory(Tr ue)

The servers send the following cache related headers :
''Cache-Control: no-cache
''Pragma: no - Cache

I don''t know if you are experienced in http headers and their behavior but
could you please test the code that''s on this page and report your result? :

http://msdn2.microsoft.com/library/9...us,vs.80).aspx

If you run the sample and go back with your browser I think you will find
that the text on the page is wrong.

Thanks in advance, Tom


re:
当您需要将其设置为true以覆盖NoCache设置时,您只需要设置HttpCachePolicy.SetAllowResponseInBrowserHistory
将SetAllowResponseInBrowserHistory设置为True不会触摸/覆盖no-cache值。它只删除了expires = -1标题。
You only need to set HttpCachePolicy.SetAllowResponseInBrowserHistory
when you need to set it to true to override the NoCache setting
Setting SetAllowResponseInBrowserHistory to True doesn''t touch/override the "no-cache"
value. It only removes the expires=-1 header.




也许这里有语义问题。


删除expires = -1 header * equals *覆盖NoCache价值。


当HttpCacheability设置为NoCache或ServerAndNoCache

时,Expires HTTP标头默认设置为-1。


NoCache和ServerAndNoCache通过设置该标题指示客户端

不在历史记录文件夹中缓存响应。


这意味着每次使用后退/前进按钮,

客户端请求新版本的响应。


当SetAllowResponseInBrowserHistory设置为True时,

删除了Expires HTTP标头。


如果你注释掉这一行:

HttpContext.Current.Response.Cache.SetAllowRespons eInBrowserHistory(True)

并在点击提交按钮和返回按钮之间切换,

您会看到此页面已过期消息不显示。


这意味着客户*已经*请求了新版本的页面,

而无需重新提交页面。 />

如果设置

HttpContext.Current.Response.Cache.SetAllowRespons eInBrowserHistory(False)

你会立即看到此页面已过期消息*显示*,
,客户需要重新提交页面。


现在,如果设置

HttpContext。 Current.Response.Cache.SetAllowRespons eInBrowserHistory(True)

并在提交按钮和后退按钮之间切换,

你会看到这个页面有过期"消息未显示,

并且页面显示而无需重新提交页面。


请求您的文档错误

单击提交按钮几次。


抛出一把扳手。

你应该只打一次才能看到它正确的行为。


文档也说错了

SetAllowResponseInBrowserHistory允许客户端缓存。


实际上它只是取消了重新提交页面的需要。


我希望这会让这个问题更加清晰。



Juan T. Llibre

ASP.NET MVP
http://asp.net.do/foros/

Foros de ASP.NET en Espa?ol

Ven,y hablemos de ASP.NET ...

======================


< To ** ******************@pandora.be>在留言中写道

新闻:a1 ************************** @ news.microsoft.c om ...胡安,

感谢您的回复。



Maybe we have a semantics problem here.

Removing the expires= -1 header *equals* overriding the "NoCache" value.

When HttpCacheability is set to NoCache or ServerAndNoCache
the Expires HTTP header is set to -1 by default.

NoCache and ServerAndNoCache instruct the client to
not cache responses in the History folder by setting that header.

This means that each time you use the back/forward buttons,
the client requests a new version of the response.

When SetAllowResponseInBrowserHistory is set to True,
the Expires HTTP header is removed.

If you comment out this line :
HttpContext.Current.Response.Cache.SetAllowRespons eInBrowserHistory(True)
and alternate between clicking the Submit button and the Back button,
you''ll see that the "This page has expired" message is not displayed.

That means that the client *has* requested a new version of the page,
without having to resubmit the page.

If you set
HttpContext.Current.Response.Cache.SetAllowRespons eInBrowserHistory(False)
you''ll see that immediately the "This page has expired" message *is* displayed,
and the client needs to resubmit the page.

Now, if you set
HttpContext.Current.Response.Cache.SetAllowRespons eInBrowserHistory(True)
and alternate between the Submit button and the Back button,
you''ll see that the "This page has expired" message is not displayed,
and the page is displayed without needing to resubmit the page.

The documentation is wrong in requesting that you
"Click the Submit button a few times".

That throws a wrench into the works.
You should only hit it once to see the correct behavior.

The documentation is also wrong when it states that
SetAllowResponseInBrowserHistory allows client-side caching.

In effect all it does is remove the need to resubmit the page.

I hope this makes this issue clearer.


Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Espa?ol
Ven, y hablemos de ASP.NET...
======================

<To********************@pandora.be> wrote in message
news:a1**************************@news.microsoft.c om... Hi Juan,

Thanks for your response.

当您需要将其设置为true以覆盖时,您只需要设置HttpCachePolicy.SetAllowResponseInBrowserHistory
NoCache设置
You only need to set HttpCachePolicy.SetAllowResponseInBrowserHistory
when you need to set it to true to override the NoCache setting



将SetAllowResponseInBrowserHistory设置为True不会触及/覆盖no-cache值。它只删除expires = -1标题。

此代码显示:
Response.Cache.SetCacheability(HttpCacheability.No Cache)
Response.Cache.SetAllowResponseInBrowserHistory(Tr ue )

服务器发送以下缓存相关标题:
''缓存控制:无缓存
''Pragma:no - 缓存

我不知道你是否对http标题及其行为有经验但是你能否测试一下这个页面上的代码并报告你的结果? :

http://msdn2.microsoft.com/library/9...us,vs.80).aspx

如果您运行示例并返回浏览器,我认为您会发现页面上的文字是错误的。

提前致谢,Tom



Setting SetAllowResponseInBrowserHistory to True doesn''t touch/override the "no-cache"
value. It only removes the expires=-1 header.

This code shows this :
Response.Cache.SetCacheability(HttpCacheability.No Cache)
Response.Cache.SetAllowResponseInBrowserHistory(Tr ue)

The servers send the following cache related headers :
''Cache-Control: no-cache
''Pragma: no - Cache

I don''t know if you are experienced in http headers and their behavior but could you
please test the code that''s on this page and report your result? :

http://msdn2.microsoft.com/library/9...us,vs.80).aspx

If you run the sample and go back with your browser I think you will find that the text
on the page is wrong.

Thanks in advance, Tom



这篇关于缓存功能不会产生预期的结果(错误?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆