【发布时间】:2018-02-01 11:09:32
【问题描述】:
我的应用程序使用 Asp.Net Identity 并在 登录 时向我的 Auth 应用程序发送一个双因素代码。这是非常标准的(因为网上有很多示例)并使用 SendCode() 方法。我的理解是“魔术”是通过这一行完成的:
// Generate the token and send it
if (!await SignInManager.SendTwoFactorCodeAsync(model.SelectedProvider))
{
View("Error");
}
我的要求是确保用户在登录后更改密码时经历相同的 2FA 过程。
我的问题是当执行发送 2FA 代码的代码时:
if (!await SignInManager.SendTwoFactorCodeAsync(model.SelectedProvider))
{
View("Error");
}
我收到错误“找不到用户 ID”:
Server Error in '/MSPortal' Application.
UserId not found.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: UserId not found.
Source Error:
Line 555:
Line 556: // Generate the token and send it
Line 557: if (!await SignInManager.SendTwoFactorCodeAsync(model.SelectedProvider))
Line 558: {
Line 559: return View("Error");
我知道 SendTwoFactorCodeAsync() 会调用 GetVerifiedUserIdAsync(),但我的理解是,现在我已经使用 2FA 登录验证了用户。
有人知道我为什么会收到这个错误吗?
谢谢。
【问题讨论】:
-
Do not post images of code or errors! 图片和屏幕截图可以很好地添加到帖子中,但请确保帖子在没有它们的情况下仍然清晰有用。如果您发布代码或错误消息的图像,请确保您也复制并粘贴或直接在帖子中输入实际代码/消息。
-
感谢 Rob 的提醒。