Cache.SetMaxAge 在 IIS 下不起作用,在 VS Dev Srv 下工作正常
我正在尝试在我的回复中添加“max-age”标头。它在我的 Visual Studio 开发服务器上运行良好,但是一旦我将应用程序移至 IIS(尝试了本地 IIS Express 和服务器上的 IIS),标头就会消失。
我的代码:
Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.SetMaxAge(new TimeSpan(1, 0, 0, 0));
VS Dev 服务器响应(一切正常):
HTTP/1.1 200 OK
Server: ASP.NET Development Server/10.0.0.0
Date: Fri, 07 Jan 2011 14:55:04 GMT
X-AspNet-Version: 2.0.50727
Cache-Control: public, max-age=86400
IIS7 响应
HTTP/1.1 200 OK
Server: Microsoft-IIS/7.5
Date: Fri, 07 Jan 2011 15:00:54 GMT
X-AspNet-Version: 2.0.50727
Cache-Control: public
PS。它是一个 ASHX 处理程序,如果重要的话......
I'm trying to add a "max-age" header to my response. It works fine on my Visual Studio Development Server, but as soon as I move the app to IIS (tried both IIS express locally and IIS on the server) - the header disappears.
My code:
Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.SetMaxAge(new TimeSpan(1, 0, 0, 0));
VS Dev server response (all works just fine):
HTTP/1.1 200 OK
Server: ASP.NET Development Server/10.0.0.0
Date: Fri, 07 Jan 2011 14:55:04 GMT
X-AspNet-Version: 2.0.50727
Cache-Control: public, max-age=86400
IIS7 Response
HTTP/1.1 200 OK
Server: Microsoft-IIS/7.5
Date: Fri, 07 Jan 2011 15:00:54 GMT
X-AspNet-Version: 2.0.50727
Cache-Control: public
PS. It's an ASHX-handler, if it matters...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
更新:2011-03-14 修复方法是确保您调用 SetSlidingExpiration(true)
如果删除 OutputCache 模块,您将获得所需的结果。我认为这是一个错误。
因此,在您的 web.config 中,您将执行以下操作:
添加:因此,还有其他信息。
以下内容剥离s-maxage
以下剥离 s-maxage
这不 - 算了......
UPDATE: 2011-03-14 The fix is ensure you call SetSlidingExpiration(true)
If you remove the OutputCache module you will get the desired result. I see this as a bug.
So, in your web.config you would do the following:
ADDED: So, there's additional information.
The following strips the s-maxage
The following strips the s-maxage
This does NOT - go figure...
解决方案:
在
web.config
中:和 en IIS PC:
使用 cmd 转到
c:\windows\system32\inetsrv
。然后执行:
Solution:
in
web.config
:and en IIS PC:
With cmd go to
c:\windows\system32\inetsrv
.Then execute:
迟来的回答但这可以帮助某人:-
Belated answered but this could help someone :-