Search code examples
c#asp.net-identity

Get all users for a certain claim?


For ASP.NET Identity 2.0:

Does anybody know how to get "all users that have a given claim assigned"?

Let's say I have a claim with type="ArticleId" and value="1".

How can I get all users that have this claim? I really couldn't figure it out .. so, thanks for any help!!


Solution

  • Check this one.

    var userContext = new ApplicationDbContext();
    
    var users = userContext.Users.ToList(); Or 
    
    var users = UserManager.Users.ToList();
    
    var userfilter = users.Where(u => u.Claims.Any(t => t.ClaimType == "ArticleId" && t.ClaimValue == "1"));