ASP.NET staticContent 配置选项不起作用

发布于 2025-01-08 19:53:03 字数 1201 浏览 1 评论 0原文

我有一个在 VS10 Dev 服务器下运行的 ASP.NET 站点。我希望某些静态内容文件能够使用较长的 max-age 缓存指令,但似乎无法使其正常工作。

我的 web.config 中有这个:

<system.webServer>
<caching enabled="true" enableKernelCache="true">    
</caching>
<httpProtocol>
  <customHeaders>
    <remove name="X-Powered-By" />
  </customHeaders>
</httpProtocol>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true"/>    

在要缓存的内容文件夹中

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

但它也不起作用,它始终与 Cache-Control: private 一起使用

那么,是否支持此 staticContent 配置?如果没有,有什么解决方法吗?如果是这样,我错过了什么?

我在所有请求中收到的标头:

Server: ASP.NET Development Server/10.0.0.0
Date: Thu, 23 Feb 2012 20:47:56 GMT
Cache-Control: private
Content-Type: application/octet-stream
Content-Length: 1043
Connection: Close

I've got an ASP.NET site running under VS10 Dev server. I'd like for certain static content files to be served with a long max-age cache directive, but can't seem to get it working.

I have this in my web.config:

<system.webServer>
<caching enabled="true" enableKernelCache="true">    
</caching>
<httpProtocol>
  <customHeaders>
    <remove name="X-Powered-By" />
  </customHeaders>
</httpProtocol>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true"/>    

And in folder of content to cache

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

But it doesn't work either, it always serves with Cache-Control: private

So, is this staticContent configuration supported? If not, any workarounds? If so, what am I missing?

Headers i get in all requests:

Server: ASP.NET Development Server/10.0.0.0
Date: Thu, 23 Feb 2012 20:47:56 GMT
Cache-Control: private
Content-Type: application/octet-stream
Content-Length: 1043
Connection: Close

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

笑脸一如从前 2025-01-15 19:53:03

我解决了这个问题!在 Web.config 中,打开 FormsAuthentication 的身份验证部分。

这非常有帮助。我通常不会发表评论,但在这种情况下,我认为这会对其他人有所帮助。就我而言,缓存控制设置为私有,我无法修改它。隐晦的答案是,当我不需要或不想要它时,我打开了身份验证。我想说的是,从搜索引擎获得提示花了更长的时间,也许这篇文章会有所帮助。

I resolved this problem! In Web.config turn on authentication section to FormsAuthentication.

This was very helpful. I don't normally post comments, but in this case, I thought it would help others. In my case, the cache-control was set to private, and I could not modify it. The obscure answer was I had authentication turned on, when I didn't need or want it. I will say that it took much longer to get a hint from search engines, maybe this text will help.

仲春光 2025-01-15 19:53:03

我解决了这个问题!在 Web.config 中,打开 FormsAuthentication 的身份验证部分。

I solved this problem! In Web.config turn on authentication section to FormsAuthentication.

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