简体   繁体   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

I Need To Set Expiry Headers In my Asp.net code.. Is there any way through which I Can Add expiry Headers through code.? 我需要在Asp.net代码中设置到期标头。是否可以通过任何方法通过代码添加到期标头?

I Have tried adding the following code in my asp page 我试图在我的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" %>

and added the following in my c# page... 并在我的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));

and added this to web,config file 并将其添加到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);

you can define it per page like below 您可以按如下所示在每页上定义它

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

or you can do it in declaritive way by doing it in your aspx page like below 或者,您也可以在aspx页面中以声明方式进行操作,如下所示

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

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

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