在使用母版页的ASP.NET页面上禁用浏览器缓存 [英] Disabling Browser Cache on ASP.NET Pages That Use Master Pages

查看:80
本文介绍了在使用母版页的ASP.NET页面上禁用浏览器缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个使用母版页的ASP.NET 2.0应用程序。我有一些

页面,不能在客户端上缓存。在ASP.NET 1.1中,我使用元标记实现了这个




< meta http-equiv =" Expires" content =" 0">

< meta http-equiv =" Pragma" content =" no-cache"

< meta http-equiv =" Cache-Control" content =" no-cache">


此标记是< headelement的一部分。我看过的示例代码

显示了如何添加表单的元标记:


< meta name =" KEYWORDS" content =" html,webdesign,javascript">


文档和文献说使用Page_Load事件处理程序中的代码

如下:


base.Master.Page.Header.Metadata.Add(" Keywords"," html,...");


但是当我尝试这个时,我得到一个编译错误,表明Header

没有Metadata属性。


如何以编程方式将所需的元标记添加到Master页面派生

aspx页面禁用客户端缓存?


一如既往,非常感谢任何指导。


Eagle

I am writing an ASP.NET 2.0 application that uses master pages. I have some
pages that must not be cached on the client. In ASP.NET 1.1 I achieved this
using metatags:

<meta http-equiv="Expires" content="0">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">

This tags are part of the <headelement. Sample code that I have seen
shows how to add metatags of the form:

<meta name="KEYWORDS" content="html, webdesign, javascript">

Documentation and literature says to use code in the Page_Load event handler
as follows:

base.Master.Page.Header.Metadata.Add("Keywords", "html,...");

However when I attempt this I get a compile error indicating that Header
does not have a Metadata property.

How can I programmatically add the needed metatags to an Master page derived
aspx page to disable client-side caching?

As always, any guidance is greatly appreciated.

Eagle

推荐答案

文章< 6C ***************** *****************@microsoft.co m> ;,

" Ea ****** @ HighFlyingBirds.com"

< Ea ************************ @ discussion.microsoft。 comwrites
In article <6C**********************************@microsoft.co m>,
"Ea******@HighFlyingBirds.com"
<Ea************************@discussions.microsoft. comwrites

>我正在编写一个使用母版页的ASP.NET 2.0应用程序。我有一些
页面,不能在客户端上缓存。在ASP.NET 1.1中,我使用元标签实现了这个目标:


< meta http-equiv =" Expires" content =" 0">

< meta http-equiv =" Pragma" content =" no-cache"

< meta http-equiv =" Cache-Control"含量= [否缓存">
>I am writing an ASP.NET 2.0 application that uses master pages. I have some
pages that must not be cached on the client. In ASP.NET 1.1 I achieved this
using metatags:

<meta http-equiv="Expires" content="0">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">



您可以在2.0中执行相同操作,或者确实在任何基于HTML的环境中执行相同操作

这是一个HTML问题,无关使用服务器端环境。

You can do the same in 2.0, or indeed in any HTML-based environment as
this is an HTML issue, nothing to do with the server-side environment.


>此标记是< headelement的一部分。我看过的示例代码
显示了如何添加表单的元标记:


< meta name =" KEYWORDS" content =" html,webdesign,javascript">

文档和文献说使用Page_Load事件处理程序中的代码
如下:


base.Master.Page.Header.Metadata.Add(" Keywords"," html,...");

然而,当我尝试这个时,我得到一个编译错误,表明Header
没有元数据属性。
>This tags are part of the <headelement. Sample code that I have seen
shows how to add metatags of the form:

<meta name="KEYWORDS" content="html, webdesign, javascript">

Documentation and literature says to use code in the Page_Load event handler
as follows:

base.Master.Page.Header.Metadata.Add("Keywords", "html,...");

However when I attempt this I get a compile error indicating that Header
does not have a Metadata property.



我似乎记得这是在测试版发布后从ASP.NET中取出的。我挣扎了一段时间,然后找到了一个更简单的方式...... b / b

I seem to remember that this was pulled from ASP.NET after a beta
release. I struggled with it for a while and then found a much easier
way...


>我如何以编程方式添加所需的metatags到一个Master页面派生的aspx页面禁用客户端缓存?
>How can I programmatically add the needed metatags to an Master page derived
aspx page to disable client-side caching?



在< headin主页面内添加contentplaceholder。然后在

中需要这些标题的任何页面,用

这些元标记填充内容控件。其他页面不需要填充(甚至没有)

内容控件。


我这么做很多,而且更容易(和更少的代码)比

神秘消失的base.Master.Page.Header.MetaData.Add()方法,

让我感到非常苛刻在第一个

的地方做到这一点。


HTH


-

Alan Silver

(此行以下添加的任何内容都与我无关)

Add a contentplaceholder inside the <headin your master page. Then in
any pages that need these headers, populate the content control with
these meta tags. Other pages don''t need to populate (or even have) the
content control.

I do this a lot and it''s much easier (and less code) than the
mysteriously vanishing base.Master.Page.Header.MetaData.Add() method,
which struck me as being a very heavy-handed way to do it in the first
place.

HTH

--
Alan Silver
(anything added below this line is nothing to do with me)


我更喜欢使用:


Response.Cache.SetNoStore();


....而不是使用元标记。



Juan T. Llibre,asp.net MVP

aspnetfaq.com: http://www.aspnetfaq.com/

asp.net faq: http://asp.net.do/faq/

foros de asp.net,en espa?ol: http://asp.net.do/foros/

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

" Alan Silver" < al ********* @ nospam.thanx.invalidwrote in message

news:YM ************** @ nospamthankyou.spam。 ..
I prefer to use :

Response.Cache.SetNoStore();

....instead of using meta tags.


Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espa?ol : http://asp.net.do/foros/
===================================
"Alan Silver" <al*********@nospam.thanx.invalidwrote in message
news:YM**************@nospamthankyou.spam...

文章< 6C *************************** *******@microsoft.co m> ;,Ea ****** @ HighFlyingBirds.com

< Ea *********** *************@discussions.microsoft。 comwrites
In article <6C**********************************@microsoft.co m>, "Ea******@HighFlyingBirds.com"
<Ea************************@discussions.microsoft. comwrites

>>我正在编写一个使用母版页的ASP.NET 2.0应用程序。我有一些
页面,不能在客户端上缓存。在ASP.NET 1.1中,我使用元标签实现了这个目标:

< meta http-equiv =" Expires" content =" 0">
< meta http-equiv =" Pragma" content =" no-cache"
< meta http-equiv =" Cache-Control"含量= [否缓存">
>>I am writing an ASP.NET 2.0 application that uses master pages. I have some
pages that must not be cached on the client. In ASP.NET 1.1 I achieved this
using metatags:

<meta http-equiv="Expires" content="0">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">



你可以在2.0或者任何基于HTML的环境中做同样的事情,因为这是一个HTML问题,

无事可做使用服务器端环境。


You can do the same in 2.0, or indeed in any HTML-based environment as this is an HTML issue,
nothing to do with the server-side environment.


>>此标记是< headelement的一部分。我看过的示例代码
显示了如何添加表单的元标记:

< meta name =" KEYWORDS" content =" html,webdesign,javascript">

文档和文献说使用Page_Load事件处理程序中的代码如下:

base.Master .Page.Header.Metadata.Add(" Keywords"," html,...");

然而,当我尝试这个时,我得到一个编译错误,表明Header
没有元数据属性。
>>This tags are part of the <headelement. Sample code that I have seen
shows how to add metatags of the form:

<meta name="KEYWORDS" content="html, webdesign, javascript">

Documentation and literature says to use code in the Page_Load event handler
as follows:

base.Master.Page.Header.Metadata.Add("Keywords", "html,...");

However when I attempt this I get a compile error indicating that Header
does not have a Metadata property.



我似乎记得这是在测试版发布后从ASP.NET中提取的。我挣扎于

a,然后找到了一个更简单的方法...


I seem to remember that this was pulled from ASP.NET after a beta release. I struggled with it for
a while and then found a much easier way...


>>我如何以编程方式添加需要元数据到一个母版页导出的
aspx页面来禁用客户端缓存?
>>How can I programmatically add the needed metatags to an Master page derived
aspx page to disable client-side caching?



在< headin您的母版页内添加一个contentplaceholder。然后在需要这些

标头的任何页面中,使用这些元标记填充内容控件。其他页面不需要填充(或者

甚至还有)内容控件。


我做了很多,而且更容易(和更少的代码)比神秘消失的

base.Master.Page.Header.MetaData.Add()方法,让我觉得这是一个非常苛刻的方式来获得
首先这样做。


HTH


-

Alan Silver

(此行下面添加的任何内容都与我无关)


Add a contentplaceholder inside the <headin your master page. Then in any pages that need these
headers, populate the content control with these meta tags. Other pages don''t need to populate (or
even have) the content control.

I do this a lot and it''s much easier (and less code) than the mysteriously vanishing
base.Master.Page.Header.MetaData.Add() method, which struck me as being a very heavy-handed way to
do it in the first place.

HTH

--
Alan Silver
(anything added below this line is nothing to do with me)



在文章< em *****中*********@TK2MSFTNGP03.phx.gbl> ;, Juan T. Llibre

< no *********** @ nowhere.comwrites
In article <em**************@TK2MSFTNGP03.phx.gbl>, Juan T. Llibre
<no***********@nowhere.comwrites

>我更喜欢使用:

Response.Cache.SetNoStore();

...而不是使用元标记。
>I prefer to use :

Response.Cache.SetNoStore();

...instead of using meta tags.



实际上做了什么?它是否会发送额外的标题,或只是为了给你编写元标记
?之前没有碰到它。


无论哪种方式,我的观点是将元标记写入内容控件

通常比使用Metadata.Add容易得多方法。你的方法

对于这个特殊问题更容易。


Ta ra

What does that actually do? Does it send extra headers, or does it just
write meta tags for you? Not come across it before.

Either way, my point was that writing meta tags into a content control
is generally much easier than using the Metadata.Add method. Your method
is even easier for this particular issue.

Ta ra


> Juan T. Llibre,asp.net MVP
aspnetfaq.com: http:// www。 aspnetfaq.com/
asp.net常见问题解答: http:// asp.net.do/faq/
foros de asp.net,en espa?ol: http://asp.net.do/foros/
======================== ===========
Alan Silver < al ********* @ nospam.thanx.invalidwrote in message
新闻:YM ************** @ nospamthankyou.spam ...
>Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espa?ol : http://asp.net.do/foros/
===================================
"Alan Silver" <al*********@nospam.thanx.invalidwrote in message
news:YM**************@nospamthankyou.spam...

>文章< 6C ***************************** *****@microsoft.co m>,
" Ea ****** @ HighFlyingBirds.com"
< Ea ************* ***********@discussions.microsoft .comwrites
>In article <6C**********************************@microsoft.co m>,
"Ea******@HighFlyingBirds.com"
<Ea************************@discussions.microsoft .comwrites

>>>我正在编写一个使用的ASP.NET 2.0应用程序母版页。我有一些
页面,不能在客户端上缓存。在ASP.NET 1.1中,我使用元标签实现了这个目标:

< meta http-equiv =" Expires" content =" 0">
< meta http-equiv =" Pragma" content =" no-cache"
< meta http-equiv =" Cache-Control"含量= [否缓存">
>>>I am writing an ASP.NET 2.0 application that uses master pages. I have some
pages that must not be cached on the client. In ASP.NET 1.1 I achieved this
using metatags:

<meta http-equiv="Expires" content="0">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">


你可以在2.0或者任何基于HTML的环境中做同样的事情,因为这是一个HTML问题,
与服务器无关 - 侧边环境。


You can do the same in 2.0, or indeed in any HTML-based environment
as this is an HTML issue,
nothing to do with the server-side environment.


>>>这个标签是< headelement的一部分。我看过的示例代码
显示了如何添加表单的元标记:

< meta name =" KEYWORDS" content =" html,webdesign,javascript">

文档和文献说使用Page_Load事件处理程序中的代码如下:

base.Master .Page.Header.Metadata.Add(" Keywords"," html,...");

然而,当我尝试这个时,我得到一个编译错误,表明Header
没有元数据属性。
>>>This tags are part of the <headelement. Sample code that I have seen
shows how to add metatags of the form:

<meta name="KEYWORDS" content="html, webdesign, javascript">

Documentation and literature says to use code in the Page_Load event handler
as follows:

base.Master.Page.Header.Metadata.Add("Keywords", "html,...");

However when I attempt this I get a compile error indicating that Header
does not have a Metadata property.


我似乎记得这是在测试版发布后从ASP.NET中提取的。我挣扎了一段时间,然后找到了一个更简单的方法...


I seem to remember that this was pulled from ASP.NET after a beta
release. I struggled with it for
a while and then found a much easier way...


>>>我如何以编程方式添加所需的metatags到一个Master页面派生的aspx页面禁用客户端缓存?
>>>How can I programmatically add the needed metatags to an Master page derived
aspx page to disable client-side caching?


在< headin主页面内添加contentplaceholder。然后在任何需要这些标题的页面中,使用这些元标记填充内容控件。其他
页面不需要填充(或者甚至没有)内容控件。

我做了很多,而且更简单(代码更少) )而不是神秘地消失了
base.Master.Page.Header.MetaData.Add()方法,这让我感到非常苛刻,这是一种非常严厉的方式来做它首先。

HTH

- Alan Silver
(此行下面添加的任何东西都与我无关)


Add a contentplaceholder inside the <headin your master page. Then
in any pages that need these
headers, populate the content control with these meta tags. Other
pages don''t need to populate (or
even have) the content control.

I do this a lot and it''s much easier (and less code) than the
mysteriously vanishing
base.Master.Page.Header.MetaData.Add() method, which struck me as
being a very heavy-handed way to
do it in the first place.

HTH

--
Alan Silver
(anything added below this line is nothing to do with me)




-

Alan Silver

(此行下方添加的任何内容均无与我合作)

--
Alan Silver
(anything added below this line is nothing to do with me)


这篇关于在使用母版页的ASP.NET页面上禁用浏览器缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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