Using Identity 2.0, I have modified to use integer as primary key following http://www.asp.net/identity/overview/extensibility/change-primary-key-for-users-in-aspnet-identity
It works great except when from the controller, I call:
User.IsUserInRole("admin");
It always returns false. I have checked the underlying table and data is fine.
However, if I do:
var t = HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>();
bool ok = t.IsInRole(User.Identity.GetUserId<int>(), "admin");
then it works fine. It seems that the problem is only in Controller.User
Also, attributes do not work, for example [Authorize(Roles = "admin")]
Somebody have had the same problem?
UPDATE:
It is nothing related with the controller, Thread.CurrentPrincipal
has the same problem:
Thread.CurrentPrincipal.IsInRole("admin");
UPDATE 2:
It seems that the problem is in the AspNetUserRoles table. Identity has added a new column, a foreign key to my extended user table. It seems redundant to me because there is UserId column. The problem is all values of this column are NULL. I think if I am able to understand how to redirect to UserId, everything will work fine.