【问题标题】:What code in ASP.NET Identity sets the user's security stamp?ASP.NET Identity 中的哪些代码设置了用户的安全标记?
【发布时间】:2015-08-10 12:06:11
【问题描述】:

安全标记是根据用户的用户名和密码生成的随机值。

在一系列方法调用之后,我将安全标记的来源追溯到Microsoft.AspNet.Identity.EntityFramework.IdentityUser<TKey, TLogin, TRole, TClaim> 类的SecurityStamp 属性。

但是,我找不到设置此值的代码。我发现这个属性只有一个设置器,即提供核心存储的 EntityFramework 层(IUserStore<..>IRoleStore<...> 等)。

// From Microsoft.AspNet.Identity.EntityFramework.UserStore<...>
public virtual Task SetSecurityStampAsync(TUser user, string stamp)
{
    this.ThrowIfDisposed();
    if (user == null)
    {
        throw new ArgumentNullException("user");
    }
    user.SecurityStamp = stamp;
    return Task.FromResult<int>(0);
}

但是,我没有找到调用SetSecurityStampAsync 方法的代码。

当用户的凭据被更改或创建新用户时,这显然会被重置。

什么代码设置了这个值?

【问题讨论】:

    标签: asp.net-identity asp.net-identity-3


    【解决方案1】:

    Microsoft.AspNet.Identity.Core 默认UserManager 大量使用这种方法。

    它使用内部方法UpdateSecurityStampInternal和公共方法UpdateSecurityStampAsync调用它。

    以下方法调用内部方法:

    • 创建异步
    • RemovePasswordAsync
    • 更新密码
    • RemoveLoginAsync
    • SetEmailAsync
    • SetPhoneNumberAsync
    • ChangePhoneNumberAsync
    • SetTwoFactorEnabledAsync

    您应该能够使用 symbolsource 获取用户管理器的源代码。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多