IIS 7.5如何添加动态HTTP过期标头 [英] IIS 7.5 How do you add a Dynamic HTTP Expires Header

查看:401
本文介绍了IIS 7.5如何添加动态HTTP过期标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在IIS 7.5中,您可以添加静态HTTP响应标头,但我想添加一个Expires标头,该标头始终指定将来7天的日期。

In IIS 7.5, you can add static HTTP Response headers, but I want to add an "Expires" header that always specifies a date that is 7 days in the future.

我正在运行php 5.4,所以我想要一个可以通过编辑web.config文件而不是一些c#代码解决方案来做到这一点的解决方案。

I'm running php 5.4, so I'd like a solution that can do this by editing the web.config file rather than some c# code solution.

我知道如何使用php添加标题,但这对静态图像文件的http标头(jpg,gif,png等)没有帮助。

I know how to add the header using php, but that won't help for static image file's http headers (jpg, gif, png, etc).

标题应该看起来像这样:

The header should look something like this:

到期:星期四,2012年5月31日10:59:25 GMT

Expires: Thu, 31 May 2012 10:59:25 GMT

怎么能我动态地总是显示未来7天的日期和时间?

How can I make it dynamically always show a date and time 7 days in the future?

编辑:

请注意我在php文件中有我想要的expires头:

Notice that I have the expires header that I want on my php files:

http://web-sniffer.net/?url=http%3A%2F%2Fwww.bestds.com

但是,我无法指定7天的日期为png文件中的Expires键提前(例如),我将来必须使用静态日期:

However, I'm not able to specify a date that is 7 days ahead for the "Expires" key on png files (for example), I'm having to use a static date far in the future:

http://web-sniffer.net/?url= http%3A%2F%2Fwww.bestds.com%2Fimage%2Ftlogo.png

推荐答案

这是一个标准IIS的功能。 HTTP Response Headers模块允许您设置此公共标头。这导致以下web.config:

This is a standard feature of IIS. The HTTP Response Headers module allows you to set this common header. This results in the following web.config:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <staticContent>
            <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" />
        </staticContent>
    </system.webServer>
</configuration>

您应该只在要发送此标头的目录中执行此操作。通常只有具有静态内容的目录。

You should do this only in the directories where you want this header to be send. Typically only directories with static content.

这篇关于IIS 7.5如何添加动态HTTP过期标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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