sonal malhotra

sonal malhotra

  • NA
  • 410
  • 51.6k

Error Role Administrator does not exist in identity mvc

Dec 12 2019 1:56 AM
hi everyone,
 
i registered name email n contact number in identity ... then i put coded in controller here below
  1. public async Task Register(RegisterViewModel model)  
  2. {  
  3. if (ModelState.IsValid)  
  4. {  
  5. var user = new ApplicationUser { Name = model.Name, UserName = model.Email, Email = model.Email, IsActive = true };  
  6. var result = await UserManager.CreateAsync(user, model.Password);  
  7. if (result.Succeeded)  
  8. {  
  9. // error shown like this below in red color  
  10. UserManager.AddToRole(user.Id,RoleName.AdministratorRoleName);  
  11. // RoleName.AdministratorRoleName ="Admin" given value  
  12. UserManager.AddClaim(user.Id,new Claim(ClaimTypes.GivenName, model.Name));  
  13. await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);   
Anybody can solve? please support me

Answers (2)