电子邮件确认-异常行为

时间:2019-03-08 12:45:23

标签: asp.net-core asp.net-core-identity email-confirmation asp.net-core-configuration

有人知道为什么会发生在我身上吗?

在这种情况下,“结果”是“成功”

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);
}

0 个答案:

没有答案