title: ASP.NET Assigning default user roles upon registration
body: <p>How can I assign default roles e.g. standard user upon user registration?</p>
  
  <p>At the moment, I can manually assign roles by editing the table in SQL server but is there a way that a default role can assigned to all users?</p>
  
  <p>I've tried using the solution posted <a href="https://stackoverflow.com/questions/21734345/how-to-create-roles-and-add-users-to-roles-in-asp-net-mvc-web-api">here</a> but it doesn't appear to work for projects using the ASP.NET Core Web Application (Visual Studio 2015).</p>
  
  <pre><code>// POST: /Account/Register
      [HttpPost]
      [AllowAnonymous]
      [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.Email, 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.Email, "Confirm your account",
                  //    $"Please confirm your account by clicking this link: &lt;a href='{callbackUrl}'&gt;link&lt;/a&gt;");
                  await _signInManager.SignInAsync(user, isPersistent: false);
                  _logger.LogInformation(3, "User created a new account with password.");
                  return RedirectToLocal(returnUrl);
              }
              AddErrors(result);
          }
  
          // If we got this far, something failed, redisplay form
          return View(model);
      }
  </code></pre>