用户注册时我有这样的代码:
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 后有人遇到过这个问题吗?
我注意到,我们需要在发送电子邮件之前对代码进行 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);