如何在 IIS7 中配置每个文件夹和扩展的静态内容缓存?

发布于 2024-08-20 07:48:43 字数 823 浏览 5 评论 0原文

我想在 IIS7 中为 ASP.NET 网站中的静态内容缓存设置规则。

我看过这些文章,其中详细介绍了如何使用 web.config 中的 元素来执行此操作:

客户端缓存 (IIS. NET)
将过期或缓存控制标头添加到静态内容中IIS(堆栈溢出)

但是,此设置似乎全局适用于所有静态内容。有没有办法只针对某些目录或扩展名执行此操作?

例如,我可能有两个需要单独缓存设置的目录:

/静态/图像
/content/pdfs

是否可以根据扩展名和文件夹设置发送缓存标头的规则(max-ageexpires 等)路径?

请注意,我必须能够通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

南冥有猫 2024-08-27 07:48:43

您可以在根 web.config 中为整个文件夹设置特定的缓存标头:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <!-- Note the use of the 'location' tag to specify which 
       folder this applies to-->
  <location path="images">
    <system.webServer>
      <staticContent>
        <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="00:00:15" />
      </staticContent>
    </system.webServer>
  </location>
</configuration>

或者您可以在内容文件夹的 web.config 文件中指定这些内容

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <staticContent>
      <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="00:00:15" />
    </staticContent>
  </system.webServer>
</configuration>

:我不知道针对特定文件类型的内置机制。

You can set specific cache-headers for a whole folder in either your root web.config:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <!-- Note the use of the 'location' tag to specify which 
       folder this applies to-->
  <location path="images">
    <system.webServer>
      <staticContent>
        <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="00:00:15" />
      </staticContent>
    </system.webServer>
  </location>
</configuration>

Or you can specify these in a web.config file in the content folder:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <staticContent>
      <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="00:00:15" />
    </staticContent>
  </system.webServer>
</configuration>

I'm not aware of a built in mechanism to target specific file types.

南烟 2024-08-27 07:48:43

您可以在每个文件的基础上执行此操作。使用路径属性包含文件名

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <location path="YourFileNameHere.xml">
        <system.webServer>
            <staticContent>
                <clientCache cacheControlMode="DisableCache" />
            </staticContent>
        </system.webServer>
    </location>
</configuration>

You can do it on a per file basis. Use the path attribute to include the filename

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <location path="YourFileNameHere.xml">
        <system.webServer>
            <staticContent>
                <clientCache cacheControlMode="DisableCache" />
            </staticContent>
        </system.webServer>
    </location>
</configuration>
Spring初心 2024-08-27 07:48:43

我遇到了同样的问题。对我来说,问题是如何配置图像的缓存限制。我遇到了这个网站,它提供了有关如何处理问题的过程的一些见解。希望它对您也有帮助
链接:[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]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文