1

我需要在我的 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" />

4

2 回答 2

0
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.Public);
HttpContext.Current.Response.Cache.SetExpires(yourCalculatedDateTime);
于 2014-02-11T08:17:05.297 回答
0

你可以像下面这样每页定义它

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

或者您可以通过在您的 aspx 页面中执行此操作以声明方式执行此操作,如下所示

<%@ OutputCache Duration="60" VaryByParam="None" %>
于 2014-02-11T08:17:56.957 回答