Asp.Net.Identity CreateAsync在UserManager中再次调用CreateAsync

时间:2018-10-17 22:40:09

标签: c# asp.net-mvc asp.net-identity

我试图了解正在发生的事情,并希望通过我自己的applicationusermanager.userManager.Edit在UserStore CreateAsync调用(db插入之前)之前对usermanager的一部分进行编辑。我在这里看不懂这段代码。

 public virtual async Task<IdentityResult> CreateAsync(TUser user, string password)
{
  this.ThrowIfDisposed();
  IUserPasswordStore<TUser, TKey> passwordStore = this.GetPasswordStore();
  if ((object) user == null)
    throw new ArgumentNullException(nameof (user));
  if (password == null)
    throw new ArgumentNullException(nameof (password));
  IdentityResult identityResult = await this.UpdatePassword(passwordStore, user, password).WithCurrentCulture<IdentityResult>();
  if (!identityResult.Succeeded)
    return identityResult;
  return await this.CreateAsync(user).WithCurrentCulture<IdentityResult>();
}

  public virtual async Task<IdentityResult> CreateAsync(TUser user)
{
  this.ThrowIfDisposed();
  await this.UpdateSecurityStampInternal(user).WithCurrentCulture();
  IdentityResult identityResult = await this.UserValidator.ValidateAsync(user).WithCurrentCulture<IdentityResult>();
  if (!identityResult.Succeeded)
    return identityResult;
  if (this.UserLockoutEnabledByDefault && this.SupportsUserLockout)
    await this.GetUserLockoutStore().SetLockoutEnabledAsync(user, true).WithCurrentCulture();
  await this.Store.CreateAsync(user).WithCurrentCulture();
  return IdentityResult.Success;
}

我正在尝试这样:

 public override async Task<IdentityResult> CreateAsync(FrUser user,string password)
    {
        IUserPasswordStore<FrUser> pws = Store as IUserPasswordStore<FrUser>;
        if ((object)user == null)
            return new IdentityResult(string.Format(SystemMessage.NewException,"CreateAsync User Null"));
        if (password == null)
            return new IdentityResult(string.Format(SystemMessage.NewException, "CreateAsync Password Null"));

        IdentityResult result = await this.UpdatePassword(pws, user, password);



        IdentityResult secondResult= await base.CreateAsync(user);

       //at last calling Store.CreateAsync(user); for db insert
        return bla bla;
    }

0 个答案:

没有答案