I am using ASP.NET MVC 5. I am creating a registration page to register an \"expert\", which I want to be a separate role from a user. I see that in the pre-generated AspNetRole
Try this.
private ApplicationUserManager _userManager;
public ApplicationUserManager UserManager
{
get
{
return _userManager ??
HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>();
}
private set
{
_userManager = value;
}
}
Register User like this.
var user = new ApplicationUser {
UserName = "John Doe",
Email = "john.doe@foo.com"
};
// params: username and password
var result = await UserManager.CreateAsync(user, "name_birthday_cheeky");
if (result.Succeeded)
{
UserManager.AddToRole(user.Id, "expert");
//code omitted for brevity
}