gpt4 book ai didi

c# - 如何清除浏览器后退按钮点击 MVC4 中的浏览器缓存?

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

我知道这是 stackoverflow 中的一个热门问题。我已经经历了每一个相同的问题,但我无法找到适合我的正确答案。这是我的注销 Controller 操作结果

    [Authorize]       
public ActionResult LogOut(User filterContext)
{
Session.Clear();
Session.Abandon();
Session.RemoveAll();
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1));
Response.Cache.SetNoStore();
FormsAuthentication.SignOut();
return RedirectToAction("Home", true);

}

它对我不起作用。我也尝试添加-

<meta http-equiv="Cache-Control" content="no-cache" /> <meta http-equiv="Pragma" content="no-cache"/> <meta http-equiv="Expires" content="0"/>

这些都没有解决我的问题。

最佳答案

您的方法的问题在于您将其设置在 MVC 应用它已经太晚的地方。以下三行代码应放在显示您不想显示的 View (因此是页面)的方法中。

Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1));
Response.Cache.SetNoStore();

如果你想在所有页面上应用“浏览器后台无缓存”行为,那么你应该把它放在 global.asax 中。

protected void Application_BeginRequest()
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1));
Response.Cache.SetNoStore();
}

关于c# - 如何清除浏览器后退按钮点击 MVC4 中的浏览器缓存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16337149/

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