public FindFirst ( Predicate |
||
match | Predicate |
The function that performs the matching logic. |
return |
ClaimsIdentity identity = (ClaimsIdentity)User.Identity; Claim givenName = identity.FindFirst(ClaimTypes.GivenName); Console.WriteLine(givenName.Value);
ClaimsIdentity identity = (ClaimsIdentity)User.Identity; Claim role = identity.FindFirst(ClaimTypes.Role); if (role != null && role.Value == "Admin") { // Perform admin-specific task }This code snippet checks if the current user has an "Admin" role claim in their identity, and performs admin-specific tasks if the claim is present. The System.Security.Claims namespace is part of the .NET Framework, and is included in the System.Security.Claims NuGet package.
public FindFirst ( Predicate |
||
match | Predicate |
The function that performs the matching logic. |
return |