mar*_*c_s 5 caching webforms cache-control asp.net-4.0
对于我们的项目,我们的客户在ASP.NET Webforms 4.0应用程序中进行了"笔测试",并发现了许多他们希望我们修复的安全问题.
到目前为止引起讨论最多的一个是发现应用程序允许缓存页面和内容,这可能会导致未经授权的用户看到他们看不到的数据(这就是"笔测试"发现的内容,大致相同).
建议的"修复"是设置cache-control和pragmaHTTP标头,no-cache以避免这种缓存,通过添加到我的web.config:
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Cache-Control" value="no-cache, no-store, must-revalidate, private"/>
<add name="Pragma" value="no-cache"/>
<add name="Expires" value="-1"/>
</customHeaders>
</httpProtocol>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
但是我有点不愿意在全球范围内这样做 - 这不也会关闭应用程序的图像,Javascript和CSS文件的任何缓存吗?这可能会对网站性能产生重大负面影响 - 不是吗?
那么我可以在"介于两者之间"做些什么吗?使用它们提供的数据阻止实际的ASP.NET页面被高速缓存,但仍然保持静态内容的缓存?如果可能的话:我必须设置哪些标题来实现这一目标?
谢谢!
如果您正在使用站点的母版页或使用扩展的Page类扩展了Page类并创建了页面,那么您可以将代码放在适当的Page_Load事件中.
Response.Cache.SetCacheability(HttpCacheability.NoCache); //Cache-Control : no-cache, Pragma : no-cache
Response.Cache.SetExpires(DateTime.Now.AddDays(-1)); //Expires : date time
Response.Cache.SetNoStore(); //Cache-Control : no-store
Response.Cache.SetProxyMaxAge(new TimeSpan(0, 0, 0)); //Cache-Control: s-maxage=0
Response.Cache.SetValidUntilExpires(false);
Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);//Cache-Control: must-revalidate
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1890 次 |
| 最近记录: |