在asp.net中设置图像到期日期 [英] Set image expire date in asp.net

查看:196
本文介绍了在asp.net中设置图像到期日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我得到一个主机时在Visual Studio和IIS7中使用asp.net。

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

我有一个文件夹,里面很少会改变,每个页面都会使用。有没有办法我可以设置某个目录,每2个小时就会过期一次,这样我可以减少传入服务器的请求数量?

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?

推荐答案

你在IIS中这样做。如果您使用的是IIS 7,则可以在web.config中添加标头。它位于system.webServer部分。

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>

这将导致所有静态内容的过期HTTP标头设置为2020年。静态内容意味着任何未通过ASP.NET引擎提供的内容,如图像,脚本文件和样式表。

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>

这将导致所有静态内容的过期HTTP标头设置为2天。

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

这篇关于在asp.net中设置图像到期日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆