C# 无过期页眉

C# 无过期页眉,c#,asp.net,caching,yslow,C#,Asp.net,Caching,Yslow,我有来自YSlow的报告: (no expires) http://static3.scirra.net/avatars/128/40cfdcbd1b1ec1842e199c97c4b85a4a.png (还有更多相似之处)。但在我的web.config中,我有: <system.webServer> <staticContent> <clientCache httpExpires="Sun, 29

我有来自YSlow的报告:

(no expires) http://static3.scirra.net/avatars/128/40cfdcbd1b1ec1842e199c97c4b85a4a.png
(还有更多相似之处)。但在我的web.config中,我有:

    <system.webServer>
            <staticContent>
                <clientCache httpExpires="Sun, 29 Mar 2020 00:00:00 GMT" cacheControlMode="UseExpires" />
            </staticContent>
            <caching>
                <profiles>
                    <add extension=".ashx" policy="CacheForTimePeriod"  kernelCachePolicy="DontCache" duration="01:00:00" />
                    <add extension=".png" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" location="Any" />
                </profiles>
            </caching>
        <rewrite>
            <rules>
                <rule name="Avatar">
                    <match url="avatars/([0-9]+)/(.*).png" />
                    <action type="Rewrite" url="gravatar.ashx?hash={R:2}&amp;size={R:1}" appendQueryString="false" />
                </rule>
            </rules>
        </rewrite>

是否应该正确添加expires标头?我的目标是:

  • ashx从Gravatar服务器获取图像
  • 服务器缓存结果1小时(与SO类似)
  • 添加Expires头,这样客户端就不会一直从我的服务器获取它

在IIS中,您可以定义HTTP头

在IIS中单击图像文件夹。然后单击HTTP响应头。然后设置公共标题

从这里,您可以检查过期的Web内容以及您选择的过期时间。您也可以对JS和CSS执行此操作。请注意哪些文件也应用了此选项。此外,如果您设置了一个很长的过期时间,并且计划更改这些文件,则可能会给您的站点带来问题

如果JS文件过期1个月,然后使用相同的名称对其进行更改,那么当用户访问您的网站时,他们将看到内容尚未过期,并且不会从web服务器请求更改的文件。当您认为内容可能会更改时,您可以通过设置适当的过期时间来解决此问题,或者您可以将版本号应用于javascript和CSS文件