ASP.Net 身份注销

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20681726/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 12:34:37  来源:igfitidea点击:

ASP.Net Identity Logout

.netasp.net-identity

提问by n0idea

How to logout an user logged in with the ASP.Net Identity system?

如何注销使用 ASP.Net Identity 系统登录的用户?

I tried:

我试过:

Authentication.SignOut();

But if I use this and then call an API marked with [Authorize](adding the token as an header) It still returns me the data (instead of Unauthorized).

但是,如果我使用它然后调用标记为[Authorize](将令牌添加为标头)的 API,它仍然会返回数据(而不是未经授权)。

回答by pranav rastogi

You need to call SignOuton the AuthenticationManagerwhich you can get from the OWIN context.

你需要调用SignOutAuthenticationManager,你可以从一开始OWIN context

var AuthenticationManager= HttpContext.GetOwinContext().Authentication;
AuthenticationManager.SignOut();

回答by O.Taaffe

In my case, because i had Authorizeattribute in my AccountControllerwith admin role at class level i had to put [AllowAnonymous]attribute to my logout method. May be a solution to you too.

就我而言,因为我在类级别的 admin 角色中有Authorize属性,所以我必须AccountController[AllowAnonymous]属性添加到我的注销方法中。也可能是你的解决方案。