MVC5默认情况下启用两因素身份验证

mar*_*rmi 5 c# asp.net asp.net-mvc asp.net-mvc-4

我有一个asp.net MVC5应用程序,其中有用户注册到系统。我一直在遵循并运行的http://www.asp.net/mvc/overview/security/aspnet-mvc-5-app-with-sms-and-email-two-factor-authentication教程。我希望在用户注册时默认启用两因素身份验证。

由此,我修改了注册模型以包括经过测试的Phone,并将其插入ASP.Net users表中没有问题。我的问题是我似乎无法解决如何默认启用两个因素

我需要await UserManager.SupportsUserTwoFactor();在register方法中使用类似的东西吗?

我的控制器是

// POST: /Account/Register
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Register(RegisterViewModel model)
{
    if (ModelState.IsValid)
    {
        var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
        var result = await UserManager.CreateAsync(user, model.Password);

        if (result.Succeeded)
        {
            //  Comment the following line to prevent log in until the user is confirmed.
           // await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);

            string code = await UserManager.GenerateEmailConfirmationTokenAsync(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 <a href=\""
               + callbackUrl + "\">here</a>");

            //Creates a Message that will then be displayed onto the 'info' view 
            ViewBag.Message = "Check your email and confirm your account, you must be confirmed "
                            + "before you can log in.";

            // var currentUser = UserManager.FindByEmail(user.Email);
            // var roleAssign = UserManager.AddToRole(currentUser.Id, "User");

            //This assigns the user to the default role. Currently it is set to the supplier
            await UserManager.AddToRoleAsync(user.Id, "Supplier");
            //Redirect the user to the following view
            return View("Info");
        }
    }

    // If we got this far, something failed, redisplay form
    return View(model);
}
Run Code Online (Sandbox Code Playgroud)

能做到吗?