gpt4 book ai didi

c# - 如何将站点范围的无缓存 header 添加到 MVC 3 应用程序

转载 作者:IT王子 更新时间:2023-10-29 04:29:14 25 4
gpt4 key购买 nike

我构建了一个 MVC3 应用程序,应用程序有很多页面,现在因为安全问题我需要在 http header 中添加无缓存设置,有没有更简单的方法来做到这一点?如果我们可以修改一个地方,那么它将适用于整个应用程序,那将是完美的。

你们能帮帮我吗?

最佳答案

如何在 Global.asaxApplication_PreSendRequestHeaders 事件中设置 Headers

编辑您可以使用 Response.Cache.SetCacheability 而不是直接设置 header 。*

void Application_PreSendRequestHeaders(Object sender, EventArgs e)
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
}

在 Fiddler 中测试。


手动设置 header 的替代方法。

void Application_PreSendRequestHeaders(Object sender, EventArgs e) {
Response.Headers.Set("Cache-Control", "no-cache");
}

关于c# - 如何将站点范围的无缓存 header 添加到 MVC 3 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7087859/

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