SignInAsync验证经过身份验证的Cookie吗?

时间:2019-09-04 06:29:32

标签: asp.net-mvc asp.net-core asp.net-identity identity

document说:

  

我们正在调用 PasswordSignInAsync 来验证并发布   身份验证Cookie

此方法是否确实验证了经过身份验证的Cookie? 验证后会怎样?我该如何获取验证结果?

换句话说:知道用户以身份登录的最佳方法是什么?

1 个答案:

答案 0 :(得分:2)

  

...验证经过身份验证的Cookie

我想这不是该句子的读法。

PasswordSignInAsync验证传递给它的凭据,如果它们有效,它将创建身份验证cookie并将其添加到响应中。

  

...知道用户以身份登录的方法

身份验证cookie用于在每个请求上重新创建Identity和Principal对象,因此对您问题的简单答案是

User.Identity.IsAuthenticated // this is a Boolean value

如果您想坚持使用SignInManager,请使用IsSignedIn(),其名称如下:

// Assuming you have an instance of SignInManager called _signInManager
_signInManager.IsSignedIn(User);

您可能想查看类似How get current user in asp.net core?

的内容