小编pet*_*ete的帖子

Asp.net 核心身份更改用户名/电子邮件

带有确认逻辑的默认身份更改用户名/电子邮件没有意义。

  • 设置需要电子邮件确认的应用程序。
  • 设置需要确认的电子邮件才能登录。
  • 然后用户更改电子邮件、错误输入电子邮件、注销。
  • 现在用户被锁定。电子邮件已更改,但需要确认才能登录且没有电子邮件确认链接,因为地址输入不正确。

我的应用程序设置错误还是 Microsoft 没有很好地设计 Identity?

  public async Task<IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return Page();
            }

            var user = await _userManager.GetUserAsync(User);
            if (user == null)
            {
                return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
            }

   //...

      var email = await _userManager.GetEmailAsync(user);
            if (Input.Email != email)
            {
                var setEmailResult = await _userManager.SetEmailAsync(user, Input.Email);
                if (!setEmailResult.Succeeded)
                {
                    var userId = await _userManager.GetUserIdAsync(user);
                    throw new InvalidOperationException($"Unexpected error occurred setting email for user with ID '{userId}'.");
                }
                StatusMessage = "<strong>Verify …
Run Code Online (Sandbox Code Playgroud)

asp.net-identity asp.net-core

4
推荐指数
1
解决办法
5741
查看次数

标签 统计

asp.net-core ×1

asp.net-identity ×1