当我在控制器中注销用户时,User.Identity.Authenticated
在返回的视图中仍然是真的。
如果我再次刷新页面,则User.Identity.Authenticated
为假
// GET: /Account/SessionExpired
[AllowAnonymous]
public ActionResult SessionExpired()
{
AuthenticationManager.SignOut();
//Clear the session
SessionHelper.Clear();
return View();
}
这是正常的吗?
谢谢
答案 0 :(得分:1)
是的,这是正常的,因为在执行操作之前检查了授权。如果您想在此之前注销,则必须先执行此操作,例如使用自定义属性
答案 1 :(得分:0)
Visual Studio中的标准MVC模板使用RedirectToAction而不是返回View。这样,浏览器会自动重定向到例如来自新请求的主页/索引操作。
答案 2 :(得分:0)
// GET: /Account/SessionExpired
[AllowAnonymous]
public ActionResult SessionExpired()
{
AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
//Clear the session
SessionHelper.Clear();
return View();
}