我正在尝试实施两因素身份验证。在双因素身份验证中,我想生成 6 位令牌并将这个 6 位令牌发送到用户邮件 ID。
问题是当我在 AccountController 中实现 Register 方法时,我在这个方法 GetEmailConfirmationTokenAsync中遇到错误。
我安装了所有必要的包像,
Microsoft.AspNet.Identity.Owin;
Microsoft.AspNet.Identity;
Microsoft.AspNet.Identity.EntityFramework;
Microsoft.Owin.Security;
Microsoft.AspNet.Identity.Sample;
Microsoft.AspNet.Identity.Core
错误:双重身份验证不包含 GetEmailConfirmationTokenAsync 的定义。
我指的是这两个链接:
代码 :
public async Task<ActionResult> Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
//var user = new ApplicationUser() { UserName = model.UserName };
var user = new ApplicationUser() { UserName = model.UserName, Email = model.Email };
var result = await UserManager.CreateAsync(user, model.Password);
//if (result.Succeeded)
//{
// await SignInAsync(user, isPersistent: false);
// return RedirectToAction("Index", "Home");
//}
if (result.Succeeded)
{
string code = await UserManager.GetEmailConfirmationTokenAsync(user.Id);
var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking this link: <a href=\"" + callbackUrl + "\">link</a>");
return View("ShowEmail");
}
else
{
AddErrors(result);
}
}
// If we got this far, something failed, redisplay form
return View(model);
}