title: Correct way of setting the role for user when he is registered with Identity
body: <p>I have a question, I'm new to identity, but still i would like to know what would be the correct way of assigning role to a user when he is registering?</p>
  
  <p>I have here a code:</p>
  
  <pre><code> [HttpPost]
      [AllowAnonymous]
      [ValidateAntiForgeryToken]
      public async Task&lt;ActionResult&gt; Register(RegisterViewModel model)
      {
          if (ModelState.IsValid)
          {
              var user = new ApplicationUser() { UserName = model.UserName };
  
              RoleManager = new RoleManager&lt;IdentityRole&gt;(new RoleStore&lt;IdentityRole&gt;(new ApplicationDbContext()));
              IdentityRole role = new IdentityRole("Admin");
              await RoleManager.CreateAsync(role);
  
              // Store Gender as Claim
              user.Claims.Add(new IdentityUserClaim() { ClaimType = ClaimTypes.Gender, ClaimValue = "Male" });
              //user.Roles.Add(new IdentityUserRole() { RoleId=role.Id, UserId=user.Id });
              var result = await UserManager.CreateAsync(user, model.Password);
              if (result.Succeeded)
              {
                  //await UserManager.AddToRoleAsync(user.Id, "Admin");
  
                  await SignInAsync(user, isPersistent: false);
                  return RedirectToAction("Index", "Home");
              }
              else
              {
                  AddErrors(result);
              }
          }
  
          // If we got this far, something failed, redisplay form
          return View(model);
      }
  </code></pre>
  
  <p>This is just a test code, but basically if i use method UserManager.AddToROleAsync( ...) it works, BUT, it only happens after the user is added, so basically i do twice the roundtrip to database.</p>
  
  <p>I tried doing it with user.Roles.Add(...) but i get an error when running it.</p>
  
  <p>So my question would be what is the most efficient and correct way of doing it?</p>