Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
928 views
in Technique[技术] by (71.8m points)

web config - IIS 7.5 How do you add a Dynamic HTTP Expires Header

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.

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.

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:

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

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

Edit:

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...