我在IdentityModels中有方法
public bool InRole(string userId, string roleName)
{
var um = LocalUserManager;
return um.IsInRole(userId, roleName);
}
当我调用此方法时,我会遇到异常:
An exception of type 'System.InvalidOperationException' occurred in mscorlib.dll but was not handled in user code
Additional information: UserId not found.
UserId参数具有正确的值。我怎么解决这个问题?
编辑: 添加LocalRoleManger
public RoleManager<IdentityRole> LocalRoleManager
{
get
{
return new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(new ApplicationDbContext()));
}
}