1

in an internet mvc 4 project, when run the project in debug mode,and login to application,the role for user wich was assigned before will recognized. the function that i use for getting user roles is :

System.Web.Security.Roles.GetRolesForUser(currentUser.Identity.Name)

but when i stop the debugging, and again run application in debug mode, user is authenticated but GetRolesForUser return string[0]. why does it occures and doesn't return role?

1 Answers1

1

I had the same issue and I fixed it change it the way of finding the roles:

var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new PlutusDbContext()));

var user = manager.FindByName(currentUser.Identity.Name);
var userRoles = manager.GetRoles(user.Id);

PS: I'm using Microsoft.AspNet.Identity 2.0.1

nramirez
  • 5,230
  • 2
  • 23
  • 39