Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法在ASP.NET标识中强制注销_Asp.net_Asp.net Mvc_Asp.net Mvc 4_Asp.net Identity_Owin - Fatal编程技术网

无法在ASP.NET标识中强制注销

无法在ASP.NET标识中强制注销,asp.net,asp.net-mvc,asp.net-mvc-4,asp.net-identity,owin,Asp.net,Asp.net Mvc,Asp.net Mvc 4,Asp.net Identity,Owin,虽然我在注销方法中尝试了以下一些方法,但用户可以在从系统注销后使用浏览器的“后退”按钮登录。使用ASP.NET标识在ASP.NET MVC中强制注销的最聪明的方法是什么 public ActionResult LogOff() { AuthenticationManager.SignOut(); //I added these lines extra in order to force logout FormsAuthentication.SignOut();

虽然我在注销方法中尝试了以下一些方法,但用户可以在从系统注销后使用浏览器的“后退”按钮登录。使用ASP.NET标识在ASP.NET MVC中强制注销的最聪明的方法是什么

public ActionResult LogOff()
{
    AuthenticationManager.SignOut();

    //I added these lines extra in order to force logout
    FormsAuthentication.SignOut(); 
    Session.Clear();
    Session.Abandon();
    Session.RemoveAll();
    //

    return RedirectToAction("Index", "Home");
}

您需要为整个项目禁用缓存。这是非常糟糕的编程。一点也不推荐

将下面的代码保存在
Global.asax
文件的
Application\u BeginRequest()

Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1));
Response.Cache.SetNoStore();
或者,您可以使用java脚本来清理缓存,以防止返回按钮,如bellow

<script>
function ClearHistory()
 {
  var backlen = history.length;
  history.go(-backlen);
  window.location.href = loggedOutPageUrl //Pass your Index Page
 }
</script>

函数ClearHistory()
{
var backlen=history.length;
历史。走(-backlen);
window.location.href=loggedOutPageUrl//传递索引页
}
请仔细阅读,有很多方法可以使用java脚本阻止后退按钮


希望有帮助。

AuthenticationManager.SignOut()需要使用参数调用,具体取决于您登录用户的方式。这通常适用于所有情况:

AuthenticationManager.SignOut(
    DefaultAuthenticationTypes.ExternalCookie,
    DefaultAuthenticationTypes.ApplicationCookie,
    DefaultAuthenticationTypes.TwoFactorCookie,
    DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie,
    DefaultAuthenticationTypes.ExternalBearer);

无需执行
FormsAuthentication.SignOut()
-这不会起任何作用。也不需要放弃会话,除非您自己使用过它-Identity不会将任何内容放入会话。

第一种方法不起作用。对于第二种方法,我应该在注销按钮中调用它吗?第一种方法会发生什么?您需要更改小时值吗?是的,您需要调用注销按钮中的第二个方法。使用第一个方法没有任何意义。我更喜欢使用第一种方法中的方法。有什么想法吗?(投票+感谢你的帮助…)你能在第一个方法中添加这一行并检查一下吗。Response.Cache.VaryByParams.IgnoreParams=true;不幸的是,它不起作用。我想如果不使用Javascript,这几乎是不可能的。谢谢,我尝试过使用这种方法,但都不起作用。很奇怪,我清除了浏览器的所有历史记录和cookies,然后登录到系统。然后注销并按下浏览器的“后退”按钮,轻松返回到需要登录到系统的上一页。还有其他想法吗?但是在上一页,如果你刷新页面,它不需要你登录吗?是的,没错。。。在这种情况下,这是唯一没有Javascript的解决方案?JS与此无关。如果有人注销了他们的饼干就不见了。即使浏览器显示上一页,他们也无法对其执行任何操作,因为任何新操作都需要cookie,而cookie已经消失。能够单击“后退”是浏览器的一项“功能”,取决于所使用的浏览器。忽略它。我只使用AuthenticationManager.SignOut()进行了测试(不带任何参数),其行为与此相同。在按下后退并返回上一页后,我单击了一个操作,但它重定向了登录页。因此,使用这种方法时有无参数似乎没有区别。有什么想法吗?