如何指定 HTTP 过期标头? (ASP.NET MVC+IIS)
我已经在 ASP.NET MVC 应用程序中使用输出缓存。
页面速度告诉我在响应标头中指定 CSS 和图像的 HTTP 缓存过期时间。
我知道 Response 对象包含一些控制缓存过期的属性。我知道这些属性可用于控制我从代码中提供的响应的 HTTP 缓存:
Response.Expires
Response.ExpiresAbsolute
Response.CacheControl
或者
Response.AddHeader("Expires", "Thu, 01 Dec 1994 16:00:00 GMT");
问题是如何为自动提供的资源设置 Expires 标头,例如图像、CSS 等?
I am already using output caching in my ASP.NET MVC application.
Page speed tells me to specify HTTP cache expiration for css and images in the response header.
I know that the Response object contains some properties that control cache expiration. I know that these properties can be used to control HTTP caching for response that I am serving from my code:
Response.Expires
Response.ExpiresAbsolute
Response.CacheControl
or alternatively
Response.AddHeader("Expires", "Thu, 01 Dec 1994 16:00:00 GMT");
The question is how do I set the Expires header for resources that are served automatically, e.g. images, css and such?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
找到它:
我需要为静态内容指定客户端缓存(在 web.config 中)。
来自 http://www.iis.net/ConfigReference/system.webServer/staticContent/客户端缓存
Found it:
I need to specify client cache for static content (in web.config).
from http://www.iis.net/ConfigReference/system.webServer/staticContent/clientCache
如果您想从要返回的资源的代码中执行此操作(即不是从 IIS 提供的静态文件),那么最好使用 Response.Cache:
我知道这不是正是您所要求的,但我通过 Google 找到了这个问题,并认为其他人可能会喜欢这个答案,因为它与您在原始问题文本中显示的 API 相关。
If you want to do it from code for a resource that you're returning (ie. not a static file being served from IIS), you're better off using
Response.Cache
:I know that's not exactly what you're asking for, but I found this question via Google and figure others might like this answer as it's related to the APIs you show in the original question text.
查看迷你静态内容交付项目。 :)
Look at mini static content delivery project. :)