asp.net-identity - IUserEmailStore 保存到数据库还是实体?

标签 asp.net-identity

我正在编写 UserStore(T) 的自定义实现,以便与较旧的数据库架构进行交互。我的 IUserEmailStore.SetEmailAsync 实现应该将此更改保存到数据库还是仅在用户实体上设置电子邮件?换句话说,身份系统在调用该方法后是否会调用UpdateAsync

最佳答案

设置电子邮件后,UserManager 会调用 UpdateAsync

public virtual async Task<IdentityResult> SetEmailAsync(TKey userId, string email)
{
    ThrowIfDisposed();
    var store = GetEmailStore();
    var user = await FindByIdAsync(userId).WithCurrentCulture();
    if (user == null)
    {
        throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
                    userId));
    }
    await store.SetEmailAsync(user, email).WithCurrentCulture();
    await store.SetEmailConfirmedAsync(user, false).WithCurrentCulture();
    await UpdateSecurityStampInternal(user).WithCurrentCulture();
    return await UpdateAsync(user).WithCurrentCulture();
}

因此,您的商店唯一需要做的是在用户对象上设置电子邮件(并且不保存)。

关于asp.net-identity - IUserEmailStore 保存到数据库还是实体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30510572/

相关文章:

asp.net-mvc-5 - 如何设置使用asp身份生成的密码重置链接的有效时间

c# - ASP.NET 核心从 appsettings 授权角色与 AD 组

c# - 如何获取特定角色的用户列表?

.net - 即使 EF 可以成功连接,Asp.Net Identity 也无法连接到数据库

c# - 你如何编辑一个用户,谁的电子邮件用户名包含一个连字符?

c# - 在 ASP.NET MVC5 Web 应用程序中向用户帐户添加声明的正确方法

c# - 从 SQL 成员资格提供程序迁移到 Indentity 2.0

c# - 在 Asp.Net Core 3 Identity 中创建自定义 SignInManager

c# - System.InvalidOperationException : 'Unable to resolve service for type ' Microsoft. Extensions.Logging.ILogger`1

asp.net-core - 使用扩展的 MVC Core Identity 用户实现自定义声明