//UserStore & RoleStore
//UserManager, RoleManer and SignInManger
var roleStore = new RoleStore
var roleManager = new RoleManager
roleManager.Create(new IdentityRole("Role1"));
UserManager.AddToRole(user.Id, "Role1");
Note: UserManager.AddToRole(user.Id, "Role1")
will add record to AspNetUserRoles but not the cookie. Later when we check the role using
User.IsInRole("Role1")
The above code will return false because it checks the cookie. We need to re-signin the user to update the cookie
SignInManager.SignIn(user, false, false);
Identity information like roles and claims are stored in the cookie when user logs in.