由於某種原因,EmailCode未在有效的雙因素身份驗證提供程序中顯示。然而,電話號碼直到我刪除它,現在什麼都沒有顯示出來。我已經調試過,它顯示在UserManager下,但由於某些奇怪的原因,GetValidTwoFactorProvidersAsync不檢索它。我已經嘗試通過繞過該方法手動添加它並手動檢索該值,但隨後會拋出Microsoft.AspNet.Identity.EmailTokenProvider不存在的錯誤消息。我無法解釋爲什麼這不起作用。ASP.NET身份2無效否雙因素提供程序存在
public async Task<ActionResult> SendCode(string returnUrl)
{
var userId = await SignInManager.GetVerifiedUserIdAsync();
if (userId == null)
{
return View("Error");
}
var userFactors = await UserManager.GetValidTwoFactorProvidersAsync(userId);
var factorOptions = userFactors.Select(purpose => new SelectListItem { Text = purpose, Value = purpose }).ToList();
return View(new SendCodeViewModel { Providers = factorOptions, ReturnUrl = returnUrl });
}
Identityconfig
manager.RegisterTwoFactorProvider("EmailCode", new Microsoft.AspNet.Identity.EmailTokenProvider<SystemUser>
{
Subject = "SecurityCode",
BodyFormat = "Your security code is {0}"
});
manager.EmailService = new EmailService();
var dataProtectionProvider = options.DataProtectionProvider;
if (dataProtectionProvider != null)
{
manager.UserTokenProvider =
new DataProtectorTokenProvider<SystemUser>(
dataProtectionProvider.Create("ASP.NET Identity"));
}
return manager;
}
只需卸載AspNet.Identity並使用Nuget Package Manager或其他任何方式重新安裝它,如何? – 2014-12-07 18:14:12
如果不摧毀大量工作,這是不可能的。刪除並重新安裝將覆蓋現有代碼。 – Rasen244 2014-12-08 04:15:25