从 .NET 8 升级到 .NET 9 后,电子邮件确认不起作用

问题描述 投票:0回答:1

用户注册时我有这样的代码:

var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
var callbackUrl = Url.Action("confirmemail", "home", new { userId = user.Id, code }, HttpContext.Request.Scheme);

// This code in here it is working
var result2 = await _userManager.ConfirmEmailAsync(user, code);

但是当我复制

callbackUrl
并从浏览器调用时,它无法确认用户。

var user = await _userManager.FindByIdAsync(userId);

if (user == null)
    return View("Error");

var result = await _userManager.ConfirmEmailAsync(user, code);

从 .NET 8 升级到 .NET 9 后有人遇到过这个问题吗?

asp.net-core asp.net-core-mvc asp.net-core-identity .net-9.0
1个回答
0
投票

我注意到,我们需要在发送电子邮件之前对代码进行 UrlEncode

var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
var encodedCode = HttpUtility.UrlEncode(code);
var callbackUrl = Url.Action("confirmemail", "home", new { userId = user.Id, code = encodedCode }, HttpContext.Request.Scheme);
© www.soinside.com 2019 - 2024. All rights reserved.