gpt4 book ai didi

caching - ASP.NET Webforms - 关闭缓存,但仅适用于 "pages",不适用于静态内容

转载 作者:行者123 更新时间:2023-12-03 16:41:48 25 4
gpt4 key购买 nike

对于我们的一个项目,我们的客户对 ASP.NET Webforms 4.0 应用程序进行了“渗透测试”,并发现了许多他们希望我们修复的安全问题。

迄今为止引起最多讨论的一个发现是该应用程序允许缓存页面和内容,这可能会导致未经授权的用户看到他们不应该看到的数据(这就是“笔测试”的发现,粗略地说)。

建议的“修复”是设置 cache-controlpragma HTTP header 到 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>

但是我有点不愿意在全局范围内这样做 - 这是否也关闭了应用程序的图像、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

关于caching - ASP.NET Webforms - 关闭缓存,但仅适用于 "pages",不适用于静态内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43718116/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com