我試圖實現雙因素身份驗證。在雙因素身份驗證中,我想生成6位數令牌,並將此6位令牌發送給用戶郵件ID。雙因素身份驗證不包含定義GetEmailConfirmationTokenAsync
問題是,當我在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);
}
希望您使用的是最新的asp.net標識2.0。檢查GenerateEmailConfirmationToken http://msdn.microsoft.com/en-us/library/dn497485%28v=vs.108%29.aspx – 2014-09-19 08:51:19
我們可以在哪裏檢查asp.net身份? – 2014-09-19 08:53:06
我正在談論Microsoft.AspNet.Identity – 2014-09-19 08:54:23