设置缓存控制aspx页面 [英] Set cache-control for aspx pages

查看:299
本文介绍了设置缓存控制aspx页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个asp.net网站,我想客户端浏览器缓存ASPX页面的HTML输出,一旦得到他们。
从阅读围绕我发现IIS7不支持此外装即用,所以我增加了以下code到我的主要主人的的OnLoad 事件页:

I have an asp.net web site and I would like the client browser to cache the HTML output of aspx pages once it gets them. From reading around I found out that IIS7 does not support this out-of-the-box, so I added the following code to the OnLoad event of my main master page:

protected override void OnLoad(EventArgs e) {
    DateTime dt = DateTime.Now.AddDays(10);
    Response.Cache.SetCacheability(HttpCacheability.Public);
    Response.Cache.SetExpires(dt);
    Response.Cache.SetMaxAge(new TimeSpan(dt.Ticks - DateTime.Now.Ticks));

    base.OnLoad(e);
}

有了这个,我仍然可以在响应头如下:

With this I still get the following in the response header:

HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Type: text/html; charset=utf-8
Content-Encoding: gzip
Expires: -1
Vary: Accept-Encoding
Date: Fri, 05 Jul 2013 14:25:03 GMT
Content-Length: 10201

也许我做了一件很久以前覆盖,但我不能,我的生活记得,如果和我所做的。没有找到任何这信息时,谷歌搜索让我觉得,也许缓存控制的aspx页面是不是一个好主意......但我需要这个,以便CloudFront的(一个CDN),让整个现场交货。

Maybe I did something a long time ago to override this, but I can't, for the life of me remember if and what I did. Not finding any info on this when searching Google makes me think that maybe cache-control for aspx pages is not a good idea... but I need this in order for cloudfront (a CDN) to allow whole site delivery.

推荐答案

某处在IIS管道(我还没有找到在哪里),无缓存头分别设置。在我的母版页,设置缓存头我想用之前,我增加了以下code Response.ClearHeaders(); 这可能不是一个很好的解决方案每一个人,因为你可能有你的反应需要已有的头,但是在我的情况下,它的伎俩。

Somewhere in the IIS pipeline (I have yet to find out where), no cache headers were set. In my master page, before setting the cache headers I wanted to use, I added the following code Response.ClearHeaders(); This might not be a good solution for everyone, since you might have some headers you need in the response already, but in my case it did the trick.

这篇关于设置缓存控制aspx页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆