ASP.NET MVC 通过表单身份验证真正注销
我在控制器上有一个注销操作,如下所示:
public ActionResult Logoff()
{
var x = Request.IsAuthenticated;
var y = User.Identity.IsAuthenticated;
FormsAuthentication.SignOut();
Session.Abandon();
var a = Request.IsAuthenticated;
var b = User.Identity.IsAuthenticated;
return View();
}
但是,x、y、a 和 b 都是 true。因此,当我的视图呈现时,它的行为仍然就像用户已登录一样。有人可以提供解决方案和/或解释吗?
I have a logoff action on a controller as so:
public ActionResult Logoff()
{
var x = Request.IsAuthenticated;
var y = User.Identity.IsAuthenticated;
FormsAuthentication.SignOut();
Session.Abandon();
var a = Request.IsAuthenticated;
var b = User.Identity.IsAuthenticated;
return View();
}
However, x, y, a, and b, are all true. So when my view renders, it still behaves as if the user is logged in. Can someone please provide a solution and/or explanation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
FormsAuthentication.SignOut()
删除身份验证 cookie,因此您需要在它之后重定向而不是返回视图,以便通知客户端:现在在
Index
操作中,用户将不再进行身份验证。FormsAuthentication.SignOut()
removes the authentication cookie, so you need to redirect after it instead of returning a view so that the client is notified:Now in the
Index
action the user will no longer be authenticated.