3

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

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

但是,我找不到设置此值的代码。我只找到了这个属性的一个设置器,那就是提供核心存储(、、等)的 EntityFrameworkIUserStore<..>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方法的代码。

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

什么代码设置了这个值?

4

1 回答 1

4

Microsoft.AspNet.Identity.Core默认使用这种UserManager方法很多。

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

以下方法调用内部方法:

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

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

于 2015-08-10T19:45:32.280 回答