IIS 8.0同时添加Expires头和Cache-Control [英] IIS 8.0 add both Expires header and Cache-Control

查看:419
本文介绍了IIS 8.0同时添加Expires头和Cache-Control的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以看到计算器添加的两种过期的Cache-Control 为他们的图像,CSS,JS等,所以我试图做同样的,我试过文章

i can see stackoverflow add's both Expires and Cache-Control for their images , css, js etc, so i am trying to do the same, i tried this article

的web.config

<location path="Content">
    <system.webServer>
      <staticContent>

    <clientCache cacheControlCustom="public" cacheControlMode="UseMaxAge" 
    cacheControlMaxAge="365.00:00:00" />

    <clientCache cacheControlMode="UseExpires" httpExpires="Mon, 01 May 2023 00:00:00 GMT" />

      </staticContent>
    </system.webServer>
</location>

当我尝试接取的内容文件夹中的CSS文件:的http://本地主机:11111 /内容/ bootstrap.min.css

我收到以下错误

错误

HTTP错误500.19 -

HTTP Error 500.19 -

内部服务器错误请求的页面不能因为页相关的配置数据进行访问
      是无效的。

Internal Server Error The requested page cannot be accessed because the related configuration data for the page is invalid.

Module           CustomErrorModule
Notification     SendResponse
Handler          StaticFile
Error Code       0x8007000d


  
  已经定义的

配置错误配置元素clientCache

Config Error Configuration element 'clientCache' already defined

我知道 clientCache 已经定义,但我担心,想知道如何设置两个Cache-Control和响应头过期?

i know clientCache already defined, but i am concerned and want to know how to set both Cache-Control and Expires in response headers ?

任何帮助将是巨大的。

更新:

由于@Vitaly库利科夫回答和评论中讨论并使用<一个href=\"http://stackoverflow.com/questions/21548334/implementing-static-files-cache-in-asp-net-mvc\">this和<一个href=\"http://stackoverflow.com/questions/20826035/how-to-set-up-both-httpexpires-and-cachecontrol-headers\">this帖子中,我来到了结论,即在IIS中,我们可以的同时设置过期和Cache-Control 在web.config中,所以我已计划使用<一个href=\"http://stackoverflow.com/questions/14769404/how-to-cache-output-of-action-method-that-returns-image-to-the-view-in-asp-net-m\">OutputCache设置为过期至少图像,并将其与 0.9毫秒的延迟的工作。希望可以帮助别人。

As @Vitaly Kulikov answered and discussed in comment and using this and this posts i came to conclusion that in IIS we can's set both Expires and Cache-Control in web.config, so i have planned to use OutputCache to set Expires for images at least and it works with 0.9 milliseconds delay. Hope helps someone.

推荐答案

根据规范有没有办法可以在同一时间有两个人。但是,你没有理由这样做,你会被罚款和他们任何人。

According to the specification there is no way you can have both of them at the same time. But you have no reason to do that, you'll be fine with any of them.

规格

如果你看看Chrome的源代码<一个href=\"https://chromium.googlesource.com/chromium/chromium/+/master/net/http/http_response_headers.cc\"相对=nofollow> code ,缓存在浏览器中有几个简单的规则

If you look into Chrome source code, caching in browser has several simple rules

首先:

在MAX-age指令优先于到期,所以如果最大年龄为present
  在响应,计算简单:freshness_lifetime = max_age_value

The max-age directive takes priority over Expires, so if max-age is present in a response, the calculation is simply: freshness_lifetime = max_age_value

二:

否则,如果在响应过期时间为present的计算方法是:freshness_lifetime = expires_value - DATE_VALUE

Otherwise, if Expires is present in the response, the calculation is: freshness_lifetime = expires_value - date_value

第三:

如果我们错过了previous步骤和缓存控制=必须重新验证,然后浏览器有一个更高速缓存规则:它缓存资源的,因为资源的最后修改日期通过了时间的10%

If we missed previous steps and "cache-control" != "must-revalidate", then browser has one more caching rule: It caches resource for 10% of a time passed since last modified date of a resource.

就是这样,没有更多的规则存在。

That's it, no more rules there.

这篇关于IIS 8.0同时添加Expires头和Cache-Control的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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