Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To retrieve users with particular claims in ASP.NET Core 6, you can use the following filter expression:

var usersWithClaim = await userManager.Users
    .Where(u => u.Claims.Any(c => c.ClaimType == "claimType" && c.ClaimValue == "claimValue"))
    .ToListAsync();

This filter expression retrieves all users from the user manager that have at least one claim matching the specified claim type and claim value.

You can replace "claimType" and "claimValue" with the actual claim type and value that you want to search for.

Note that you will need to inject the user manager into your controller or service using dependency injection. Also, make sure to import the necessary namespaces, such as Microsoft.AspNetCore.Identity and System.Linq.