Updating the Manage View Index.cshtml Razor view:
(note: do not only delete comments from the outgoing code but also use the code below.)
@model MvcPWy.Models.IndexViewModel
@{
ViewBag.Title = "Manage";
}
Check whether the EnableTwoFactorAuthentication and DisableTwoFactorAuthentication action methods in the ManageController have the attribute[ValidateAntiForgeryToken]:
[HttpPost,ValidateAntiForgeryToken]
public async Task EnableTwoFactorAuthentication()
{
await UserManager.SetTwoFactorEnabledAsync(User.Identity.GetUserId(), true);
var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());
if (user != null)
{
await SignInAsync(user, isPersistent: false);
}
return RedirectToAction("Index", "Manage");
}
[HttpPost, ValidateAntiForgeryToken]
public async Task DisableTwoFactorAuthentication()
{
await UserManager.SetTwoFactorEnabledAsync(User.Identity.GetUserId(), false);
var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());
if (user != null)
{
await SignInAsync(user, isPersistent: false);
}
return RedirectToAction("Index", "Manage");
}
public ActionResult AddPhoneNumber()
{
return View();
}
- Run the application and sign in with your already registered account.
- Click your User ID, which will enable the Index method of action within. Manage controller.
- Click Add.
- The AddPhoneNumber action method shows a dialogue box to enter a phone number that can receive SMS messages.
- In a few seconds, you will receive an SMS with the verification code. Enter it, then tap Submit.
- Your telephone number has been added to the Manage view.