繁体   English   中英

有什么方法可以在asp.net中设置到期标头,而无需在IIS 6 Configuration Manager中进行更改

[英]Is there any way to set expiry headers in asp.net without making changes in IIS 6 Configuration Manager

我需要在Asp.net代码中设置到期标头。是否可以通过任何方法通过代码添加到期标头?

我试图在我的asp页面中添加以下代码

<% System.Web.HttpContext.Current.Response.AddHeader( "Cache-Control","no-cache"); System.Web.HttpContext.Current.Response.Expires = 0; System.Web.HttpContext.Current.Response.Cache.SetNoStore(); System.Web.HttpContext.Current.Response.AddHeader("Pragma", "no-cache");%>

<%@ OutputCache Duration="86400" Location="Client" VaryByParam="None" %>

并在我的C#页面中添加了以下内容...

Response.AddHeader("Expires", "Thu, 01 Dec 2014 16:00:00 GMT");


Response.Cache.SetCacheability(HttpCacheability.Public); Response.Cache.SetMaxAge(TimeSpan.FromSeconds(3600)); Response.Cache.SetExpires(DateTime.UtcNow.AddSeconds(3600));

并将其添加到web,config文件

<clientCache httpExpires="Sun, 29 Mar 2020 00:00:00 GMT" cacheControlMode="UseExpires" />

HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.Public);
HttpContext.Current.Response.Cache.SetExpires(yourCalculatedDateTime);

您可以按如下所示在每页上定义它

Response.Cache.SetExpires(DateTime.Now.AddSeconds(60));
Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.SetValidUntilExpires(true);

或者,您也可以在aspx页面中以声明方式进行操作,如下所示

<%@ OutputCache Duration="60" VaryByParam="None" %>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM