HttpContext.SignInAsync vs. SigninManger.SignInAsync



有人可以向我解释他们在后台做什么吗?我在SecurityStamp中使用HttpContext.SignInAsync时遇到了问题。

使用SigninManger.SignInAsync后,错误再也没有发生过。

你能向我解释一下这些变体之间的区别是什么吗?我想了解HttpContext.SignInAsync为什么会有这样的行为。

我对其中的区别很好奇,所以我检查了源代码。(深层链接(

SignInManager.SignInAsync定义如下,其中Context HttpContext

/// <summary>
/// Signs in the specified <paramref name="user"/>.
/// </summary>
/// <param name="user">The user to sign-in.</param>
/// <param name="authenticationProperties">Properties applied to the login and authentication cookie.</param>
/// <param name="authenticationMethod">Name of the method used to authenticate the user.</param>
/// <returns>The task object representing the asynchronous operation.</returns>
public virtual Task SignInAsync(TUser user, AuthenticationProperties authenticationProperties, string authenticationMethod = null)
{
    var additionalClaims = new List<Claim>();
    if (authenticationMethod != null)
    {
        additionalClaims.Add(new Claim(ClaimTypes.AuthenticationMethod, authenticationMethod));
    }
    return SignInWithClaimsAsync(user, authenticationProperties, additionalClaims);
}
public virtual async Task SignInWithClaimsAsync(TUser user, AuthenticationProperties authenticationProperties, IEnumerable<Claim> additionalClaims)
{
    var userPrincipal = await CreateUserPrincipalAsync(user);
    foreach (var claim in additionalClaims)
    {
        userPrincipal.Identities.First().AddClaim(claim);
    }
    await Context.SignInAsync(IdentityConstants.ApplicationScheme,
        userPrincipal,
        authenticationProperties ?? new AuthenticationProperties());
}

因此,它只是使用某些选项调用HttpContext.SignInAsync并在某些情况下添加声明

相关内容

  • 没有找到相关文章

最新更新