Asp mvc角色系统

时间:2016-09-27 19:21:58

标签: model-view-controller roles

我在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()));

        }
    }

0 个答案:

没有答案