We want browser caching on the content from certain folders on the site (images / styles / scripts) and setting them to remain fresh for 7 days. Also, we use a CMS called Ektron.
Here is the code we were using, any ideas as to why this isn't working?
From global.asax
void Application_PreSendRequestHeaders(object sender, EventArgs e)
{
System.Web.HttpCacheability cachelevel = System.Web.HttpCacheability.Private;
if (Request.FilePath.ToLower().StartsWith("/images") || Request.FilePath.ToLower().StartsWith("/styles") ||
Request.FilePath.ToLower().StartsWith("/js") || Request.FilePath.ToLower().StartsWith("/scripts"))
{
cachelevel = System.Web.HttpCacheability.Public;
if (cachelevel == System.Web.HttpCacheability.Public) Response.Cache.SetCacheability(cachelevel);
var staticExtensions = new List<string> { ".js", ".css", ".jpg", ".gif", ".png" };
if (staticExtensions.Any(ext => Request.FilePath.ToLower().EndsWith(ext)))
{
Response.Cache.SetMaxAge(TimeSpan.FromDays(7));
}
}