有人知道为什么会发生在我身上吗?
在这种情况下,“结果”是“成功” :
public async Task<IActionResult> TestConfirmInSameRequest(string userId)
{
var user = await this._userManager.FindByIdAsync(userId);
var code = await this._userManager.GenerateEmailConfirmationTokenAsync(user);
var result = await this._userManager.ConfirmEmailAsync(user, code);
var newLocation = ...
return Redirect(newLocation);
}
在这种情况下,“结果”始终为“ InvalidToken” (即使我手动复制原始代码并对其进行测试)
public async Task<IActionResult> ConfirmEmail(string userId, string code)
{
var user = await this._userManager.FindByIdAsync(userId);
var result = await this._userManager.ConfirmEmailAsync(user, code);
var newLocation = ...;
return Redirect(newLocation);
}
protected async Task SendConfirmationEmail(string userId, bool originMobile)
{
var user = await this._userManager.FindByIdAsync(userId);
var code = await this._userManager.GenerateEmailConfirmationTokenAsync(user);
var encodedCode = HttpUtility.UrlEncode(code);
var callbackUrl = $"https://.../api/account/confirmemail?userId={userId}&code={encodedCode}";
await this._userService.SendConfirmationEmailAsync(userId, callbackUrl);
}