【发布时间】:2020-04-10 10:28:37
【问题描述】:
我正在开发 ASP.NET Core MVC Web 应用程序。我为注销创建了一个控制器,它工作正常。当用户单击注销时,我正在尝试删除缓存。我使用了下面给定的代码,但在缓存删除的情况下它不起作用。这是我的注销控制器代码:
[HttpGet]
[ResponseCache(Location = ResponseCacheLocation.None, NoStore = true)]
public ActionResult Logout()
{
HttpContext.Session.Clear();
return RedirectToAction("Login", "Login");
}
我什至尝试使用下面给出的代码来删除缓存,但它也不起作用。
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1));
Response.Cache.SetNoStore();
// Clears the session at the end of request
Session.Abandon();
当用户在 Asp .Net Core 应用程序中注销时,如何删除缓存或防止单击返回按钮。
【问题讨论】:
-
Session.Clear() 只是清除会话变量,它不会将任何人注销。用户保持登录状态
-
查看Introduction to Identity 文档。注销页面已经可用。如果需要,您可以自定义它。这在Logout section 中显示。实际的注销操作是通过调用 SigningManager.SignoutAsync 来执行的
-
@PanagiotisKanavos 如何在我的代码中使用 SignOutAsync()?
标签: c# asp.net api asp.net-core-mvc visual-studio-2019