Set image expire date in asp.net

2019-05-11 09:05发布

Using asp.net in visual studios and IIS7 when i get a host.

I have a folder full of icons that will rarely change and is used on every page. Is there a way i can set a certain directory to expire something like once every 2 or so hours so i can decrease the amount of incoming request to the server?

1条回答
疯言疯语
2楼-- · 2019-05-11 09:27

You do that in IIS. If you are using IIS 7, you can add the header in your web.config. It’s in the system.webServer section.

<staticContent>
    <clientCache httpExpires="Sun, 29 Mar 2020 00:00:00 GMT" cacheControlMode="UseExpires" />
</staticContent>

This will cause all static content to have an expires HTTP header set to the year 2020. Static content means anything that isn’t served through the ASP.NET engine such as images, script files and styles sheets.

Or to use a relative expiration, use this:

<staticContent>
    <clientCache cacheControlMaxAge ="2.00:00:00" cacheControlMode="UseMaxAge" />
</staticContent>

This will cause all static content to have an expires HTTP header set to 2 days.

查看更多
登录 后发表回答