FormsAuthentication.SignOut() 后,并未真正退出的原因

使用Asp.net开发,使用Forms验证,在退出按钮里写 FormsAuthentication.SignOut() 并清除Session和Cookie,发现退出后,使用Request.IsAuthenticated获取到的值依然是True。

解决办法:

FormsAuthentication.SignOut() 必须写在逻辑最后,在执行FormsAuthentication.SignOut()方法后,不能再进行清除Cookie的操作。

或者写入session清除更明了有效。

  1. public ActionResultLogout()
  2. {
  3. FormsAuthentication.SignOut();
  4. Session.RemoveAll();
  5. }

参考文章http://demo.tc/Post/700

原文地址:https://www.cnblogs.com/Raywang80s/p/2722550.html