[英]how to add Expires headers to asp.net without changing settings in IIS 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.