Asp.net静态内容总是缓存 [英] Asp.net static content always caches

查看:83
本文介绍了Asp.net静态内容总是缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用ASP.NET MVC 5和angular.js的项目

最近(虽然我不确定何时)我的angular.js视图的更改未反映在浏览器中。

当我查看Chrome中的开发人员工具时,它表明它是直接从缓存中提取的。 Last-Modified标题似乎有几天了,ASP.NET服务器返回304 Not Modified for html文件。



有没有人知道为什么我的静态内容(特别是html文件)在* *实际发生变化时被浏览器缓存。



我尝试过:



我修改了Web.config,如下所示:

 <   system.webServer  >  
...
< 缓存 已启用 = false / >
< staticContent >
< clientCache cacheControlMode = DisableCache / >
< / staticContent > ;
< / system.webServer >



然而,这似乎没有任何区别。

我还检查过文件系统正在识别我的变化;文件上的修改日期比服务器返回的最后修改更新。

解决方案

请查看以下指南。



您可以使用标题来控制缓存。



这是一组典型的响应标头的样子当缓存被禁用时。



 HTTP / 1.1 200 OK 
服务器:Apache
X-Rack-缓存:错过
ETag:e6811cdbcedf972c5e8105a89f637d39-gzip
状态:200
内容类型:text / html; charset = utf-8
到期日:2013年4月29日星期一21:44:55 GMT
Cache-Control:max-age = 0,no-cache,no-store
Pragma:no -cache
日期:2013年4月29日星期一21:44:55 GMT





这是来自以下文章,内容包括深入探讨这个问题。



HTTP缓存标题初学者指南| Mobify [ ^


I have a project that uses ASP.NET MVC 5 and angular.js
Recently (though I'm not sure when) changes to my angular.js views are not being reflected in the browser.
When I look at the developer tools in Chrome, it indicates that it is pulling it directly from cache. The Last-Modified header appears to be a couple days old and the ASP.NET server is returning 304 Not Modified for the html file.

Does anyone have any clue why my static content (specifically html files) are being cached by the browser when there *are* in fact changes.

What I have tried:

I have modified the Web.config like so:

<system.webServer>
    ...
    <caching enabled="false" />
    <staticContent>
      <clientCache cacheControlMode="DisableCache"/>
    </staticContent>
</system.webServer>


However, that doesn't seem to make any difference.
I have also checked that the file system is recognizing my changes; the "date modified" on the files are much more recent than the "last-modified" being returned by the server.

解决方案

Take a look at the following guide.

You can control caching by using headers.

Here's what a set of typical response headers look like when the caching is disabled.

HTTP/1.1 200 OK
Server: Apache
X-Rack-Cache: miss
ETag: "e6811cdbcedf972c5e8105a89f637d39-gzip"
Status: 200
Content-Type: text/html; charset=utf-8
Expires: Mon, 29 Apr 2013 21:44:55 GMT
Cache-Control: max-age=0, no-cache, no-store
Pragma: no-cache
Date: Mon, 29 Apr 2013 21:44:55 GMT



This is from the following article which covers the subject in depth.

A Beginner's Guide to HTTP Cache Headers | Mobify[^]


这篇关于Asp.net静态内容总是缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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