I have code like this when a user registers:
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);
But when I copy the callbackUrl
and call from the browser, it is not able to confirm the user.
var user = await _userManager.FindByIdAsync(userId);
if (user == null)
return View("Error");
var result = await _userManager.ConfirmEmailAsync(user, code);
Has anyone encountered this issue after upgrade from .NET 8 to .NET 9?
I notice, we need to UrlEncode the code before sending the email
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);