有没有办法在不更改 IIS 6 配置管理器的情况下在 asp.net 中设置过期标头



我需要在我的 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");
AND

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

并将其添加到Web,配置文件

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

您可以按页面定义它,如下所示

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

或者,您可以通过在 ASPX 页面中以声明方式执行此操作,

如下所示
<%@ OutputCache Duration="60" VaryByParam="None" %>
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.Public);
HttpContext.Current.Response.Cache.SetExpires(yourCalculatedDateTime);

最新更新