2012-02-23 50 views
2

我有一个在VS10 Dev服务器下运行的ASP.NET网站。我希望某些静态内容文件可以用最长时间的缓存指令提供,但似乎无法使其工作。ASP.NET静态内容配置选项不起作用

我有这个在我的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 
+0

您是否在web.config中有

2012-02-23 22:59:40

+0

你看过这个吗? http://www.iis.net/ConfigReference/system.webServer/staticContent/clientCache – Aristos 2012-02-23 23:07:47

+0

也许你在你的程序中的其他地方设置标题(例如global.asax) – Aristos 2012-02-23 23:09:31

回答

0

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

+0

你可能想稍微详细说明答案,然后接受它让别人知道你的问题现在已经解决了。 – dasblinkenlight 2013-01-30 17:25:14

1

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

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