IIS 7.5 How do you add a Dynamic HTTP Expires Header

断了今生、忘了曾经 提交于 2019-12-17 21:19:05

问题


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


回答1:


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.




回答2:


You can only add dynamic expires header using program code.

Source: The Microsoft IIS Site

You should use Cache-Control max-age instead, like suggested in the other answer.



来源:https://stackoverflow.com/questions/10825497/iis-7-5-how-do-you-add-a-dynamic-http-expires-header

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!