title: Account Register on ASP net core not registering user
body: <p>Hi I'm trying to make a website for my company and I'm trying to get user accounts to work however everytime I try to register a new user on the register page it does not create a user in the database. I have confirmed this multiple times by looking in the SSOX localDB. The website is written in asp dotnet core. The only modifications I have done to this after the authentication template is added a user column using Entity Framework code first, and have added the user input into forms and the controllers accordingly. I have also followed the tutorial on <a href="https://docs.asp.net/en/latest/security/authentication/accconfirm.html" rel="nofollow">https://docs.asp.net/en/latest/security/authentication/accconfirm.html</a>
  to add account confirmation.</p>
  
  <p>As dotnetcore asp is fairly new there is not many questions asked and I have searched for my problem on google and also on stack but have failed to find an answer to my problem. I have included my code for the Account Controller, Register View Model and Register View below.</p>
  
  <p>If anybody knows of a solution I would be very greatful.</p>
  
  <p>Account Controller Register code: </p>
  
  <pre><code>// GET: /Account/Register
              [HttpGet]
              [AllowAnonymous]
              public IActionResult Register(string returnUrl = null)
              {
                  ViewData["ReturnUrl"] = returnUrl;
                  return View();
              }
  
              //
              // POST: /Account/Register
              [HttpPost]
              [Authorize]
              [ValidateAntiForgeryToken]
              public async Task&lt;IActionResult&gt; Register(RegisterViewModel model, string returnUrl = null)
              {
                  ViewData["ReturnUrl"] = returnUrl;
                  if (ModelState.IsValid)
                  {
                      var user = new ApplicationUser { UserName = model.UserName, Email = model.Email };
                      var result = await _userManager.CreateAsync(user, model.Password);
                      if (result.Succeeded)
                      {
  
                          // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=532713
                          // Send an email with this link
                          var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
                          var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme);
                          await _emailSender.SendEmailAsync(model.UserName, model.Email, "Confirm your account", $"Please confirm your account by clicking this link: &lt;a href='{callbackUrl}'&gt;link&lt;/a&gt;");
                          //Line commented to prevent user logging in without confirming account. //await _signInManager.SignInAsync(user, isPersistent: false);
                          _logger.LogInformation(3, $"User {user.Id} created a new account");
                          return RedirectToLocal(returnUrl);
                      }
                      AddErrors(result);
                  }
  
                  // If we got this far, something failed, redisplay form
                  return View(model);
              }
  </code></pre>
  
  <p>Here is my RegisterViewModel Code:</p>
  
  <pre><code>using System.ComponentModel.DataAnnotations;
  
  namespace MainSite.Models.AccountViewModels
  {
      public class RegisterViewModel
      {
          [Required]
          [Display(Name = "Username")]
          public string UserName { get; set; }
  
          [Required]
          [EmailAddress]
          [Display(Name = "Email")]
          public string Email { get; set; }
  
          [Required]
          [StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)]
          [DataType(DataType.Password)]
          [Display(Name = "Password")]
          public string Password { get; set; }
  
          [DataType(DataType.Password)]
          [Display(Name = "Confirm password")]
          [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
          public string ConfirmPassword { get; set; }
      }
  }
  </code></pre>
  
  <p>And my Register View code:</p>
  
  <pre><code>@model RegisterViewModel
  @{
      ViewData["Title"] = "Register";
  }
  
  &lt;h2&gt;@ViewData["Title"].&lt;/h2&gt;
  
  &lt;form asp-controller="Account" asp-action="Register" asp-route-returnurl="@ViewData["ReturnUrl"]" method="post" class="form-horizontal"&gt;
      &lt;h4&gt;Create a new account.&lt;/h4&gt;
      &lt;hr /&gt;
      &lt;div asp-validation-summary="All" class="text-danger"&gt;&lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;label asp-for="UserName" class="col-md-2 control-label"&gt;&lt;/label&gt;
          &lt;div class="col-md-10"&gt;
              &lt;input asp-for="UserName" class="form-control" /&gt;
              &lt;span asp-validation-for="UserName" class="text-danger"&gt;&lt;/span&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;label asp-for="Email" class="col-md-2 control-label"&gt;&lt;/label&gt;
          &lt;div class="col-md-10"&gt;
              &lt;input asp-for="Email" class="form-control" /&gt;
              &lt;span asp-validation-for="Email" class="text-danger"&gt;&lt;/span&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;label asp-for="Password" class="col-md-2 control-label"&gt;&lt;/label&gt;
          &lt;div class="col-md-10"&gt;
              &lt;input asp-for="Password" class="form-control" /&gt;
              &lt;span asp-validation-for="Password" class="text-danger"&gt;&lt;/span&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;label asp-for="ConfirmPassword" class="col-md-2 control-label"&gt;&lt;/label&gt;
          &lt;div class="col-md-10"&gt;
              &lt;input asp-for="ConfirmPassword" class="form-control" /&gt;
              &lt;span asp-validation-for="ConfirmPassword" class="text-danger"&gt;&lt;/span&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;div class="col-md-offset-2 col-md-10"&gt;
              &lt;button type="submit" class="btn btn-default"&gt;Register&lt;/button&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  
  @section Scripts {
      @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); }
  }
  </code></pre>