0

The roles stored in the database are not recovered by UserManager.GetRoles(userId);

I have use Identity before and never happend this... don't know what I have done this time or what's happening...

How I create user and his role:

var result = manager.Create(applicationUser, model.Password);
if (result.Succeeded)
{
   var userRegistered = manager.FindByName(applicationUser.UserName);

   var roleResult = manager.AddToRole(userRegistered.Id, model.Rol);

   if(roleResult.Succeeded){return true;}
}

This return true and data store on db tables ( user, and userRole) but..

When I login I can't access to actions... with role authorization...

  [Authorize(Roles = "Admin")]
  public ActionResult Delete(string id)

On debug I have checked that user have no items on Roles list !!!

Posts I've seen haven't helped me solve the problem , any idea why it does not work ?

Im working with Identity 2.1 ASP MVC 5 on VS 2013comm

Thanks for your help ;)

Luke
  • 22,826
  • 31
  • 110
  • 193

0 Answers0