如何在 IIS7 中配置每个文件夹和扩展的静态内容缓存?
我想在 IIS7 中为 ASP.NET 网站中的静态内容缓存设置规则。
我看过这些文章,其中详细介绍了如何使用 web.config
中的
元素来执行此操作:
但是,此设置似乎全局适用于所有静态内容。有没有办法只针对某些目录或扩展名执行此操作?
例如,我可能有两个需要单独缓存设置的目录:
/静态/图像
/content/pdfs
是否可以根据扩展名和文件夹设置发送缓存标头的规则(max-age
、expires
等)路径?
请注意,我必须能够通过 web.config
执行此操作,因为我无权访问 IIS 控制台。
I would like to set up rules in IIS7 for static content caching in my ASP.NET website.
I have seen these articles, which details how to do it using the <clientCache />
element in web.config
:
Client Cache
<clientCache>
(IIS.NET)
Add Expires or Cache Control Header to static content in IIS (Stack Overflow)
However, this setting appears to apply globally to all static content. Is there a way to do this just for certain directories or extensions?
For example, I may have two directories which need separate cache settings:
/static/images
/content/pdfs
Is it possible to set up rules for sending cache headers (max-age
, expires
, etc) based on extensions and folder paths?
Please note, I must be able to do this via web.config
because I don't have access to the IIS console.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以在根
web.config
中为整个文件夹设置特定的缓存标头:或者您可以在内容文件夹的
web.config
文件中指定这些内容:我不知道针对特定文件类型的内置机制。
You can set specific cache-headers for a whole folder in either your root
web.config
:Or you can specify these in a
web.config
file in the content folder:I'm not aware of a built in mechanism to target specific file types.
您可以在每个文件的基础上执行此操作。使用路径属性包含文件名
You can do it on a per file basis. Use the path attribute to include the filename
我遇到了同样的问题。对我来说,问题是如何配置图像的缓存限制。我遇到了这个网站,它提供了有关如何处理问题的过程的一些见解。希望它对您也有帮助
链接:[https://varvy.com/pagespeed/cache-control.html]
I had the same issue.For me the problem was how to configure a cache limit to images.And i came across this site which gave some insights to the procedure on how the issue can be handled.Hope it will be helpful for you too
Link:[https://varvy.com/pagespeed/cache-control.html]