ASP.NET staticContent 配置选项不起作用
我有一个在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这非常有帮助。我通常不会发表评论,但在这种情况下,我认为这会对其他人有所帮助。就我而言,缓存控制设置为私有,我无法修改它。隐晦的答案是,当我不需要或不想要它时,我打开了身份验证。我想说的是,从搜索引擎获得提示花了更长的时间,也许这篇文章会有所帮助。
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.
我解决了这个问题!在 Web.config 中,打开 FormsAuthentication 的身份验证部分。
I solved this problem! In Web.config turn on authentication section to FormsAuthentication.