我们的调查向我们表明,并非所有浏览器都以统一的方式尊重http缓存指令.
出于安全原因,我们不希望在我们的应用程序某些网页缓存,有史以来,通过Web浏览器.这必须至少适用于以下浏览器:
我们的要求来自安全测试.从我们的网站注销后,您可以按后退按钮查看缓存页面.
我在web.config中有这个:
<system.webServer>
<httpProtocol>
<customHeaders>
<clear />
<add name="Cache-Control" value="max-age=30,public" />
</customHeaders>
</httpProtocol>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
但是当我加载页面时,这是响应头:
Cache-Control: private,max-age=30,public
Run Code Online (Sandbox Code Playgroud)
它是一个ASP.NET MVC应用程序,控制器没有指定任何位置的缓存指令.
历史:
出于安全考虑,我们的组织希望通过向 IIS 添加 HTTP 标头来禁用缓存。
过期:-1
Pragma:无缓存
缓存控制:无缓存、无存储
添加这些标头会导致 MIME“ application/vnd.ms-excel ”响应类型在IE6中对SSL进行故障转移。Microsoft 承认这是一个错误 ( http://support.microsoft.com/kb/323308 ),并且他们的解决方案也有效。然而,该解决方案必须作为补丁在整个组织中推广,并且面临更高管理层的阻力。
问题:
同时,我们尝试通过使用PreSendRequestHeaders()函数上的HTTPModules覆盖 IIS 设置 MIME 类型“application/vnd.ms-excel”页面的 HTTP 标头来找到替代方案
//this is just a sample code
public void Init(HttpApplication context)
{
context.PreSendRequestHeaders += new EventHandler(context_PreSendRequestHeaders);
}
protected void context_PreSendRequestHeaders(object sender, EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
if(application.Response.ContentType == "application/vnd.ms-excel; name=DataExport.xls")
{
application.Response.ClearHeaders();
application.Response.ContentType = "application/vnd.ms-excel; name=DataExport.xls";
application.Response.AddHeader("Content-Transfer", "Encoding: base64");
application.Response.AddHeader("Content-Disposition", "attachment;filename=DataExport.xls");
application.Response.AddHeader("cache-control","private");
}
}
Run Code Online (Sandbox Code Playgroud)
即使使用 ClearHeaders() 清除标头后,IIS 仍会在发送响应之前附加缓存标头。 …
我的IIS7 web.config设置为以下静态资源文件夹(不在ASP.NET应用程序或任何内容中):
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<staticContent>
<clientCache cacheControlCustom="public" cacheControlMode="UseMaxAge" cacheControlMaxAge="500.00:00:00" />
</staticContent>
<httpProtocol allowKeepAlive="false" />
</system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud)
当我尝试访问Silverlight .XAP文件时,我希望IIS告诉浏览器它可以缓存500天.
但是,这是缓存头:
Cache-Control: no-cache,public,max-age=43200000
为什么IIS仍然no-cache使用上述配置文件添加到此标头?
http-headers ×3
iis-7 ×2
asp.net ×1
caching ×1
http ×1
https ×1
iis-6 ×1
silverlight ×1
web-config ×1