简体   繁体   中英

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.?

I Have tried adding the following code in my asp page

<% 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...

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

<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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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