ClaimsIdentity.FindFirst Method

Definition

Retrieves the first claim that matches a specified condition.

Overloads

FindFirst(Predicate<Claim>)

Retrieves the first claim that is matched by the specified predicate.

FindFirst(String)

Retrieves the first claim with the specified claim type.

FindFirst(Predicate<Claim>)

Source:
ClaimsIdentity.cs
Source:
ClaimsIdentity.cs
Source:
ClaimsIdentity.cs

Retrieves the first claim that is matched by the specified predicate.

C#
public virtual System.Security.Claims.Claim FindFirst(Predicate<System.Security.Claims.Claim> match);
C#
public virtual System.Security.Claims.Claim? FindFirst(Predicate<System.Security.Claims.Claim> match);

Parameters

match
Predicate<Claim>

The function that performs the matching logic.

Returns

The first matching claim or null if no match is found.

Exceptions

match is null.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1
UWP 10.0

FindFirst(String)

Source:
ClaimsIdentity.cs
Source:
ClaimsIdentity.cs
Source:
ClaimsIdentity.cs

Retrieves the first claim with the specified claim type.

C#
public virtual System.Security.Claims.Claim FindFirst(string type);
C#
public virtual System.Security.Claims.Claim? FindFirst(string type);

Parameters

type
String

The claim type to match.

Returns

The first matching claim or null if no match is found.

Exceptions

type is null.

Remarks

The comparison is done in StringComparison.OrdinalIgnoreCase mode.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1
UWP 10.0