ClaimsPrincipal.Identity Property

Definition

Gets the primary claims identity associated with this claims principal.

C#
public virtual System.Security.Principal.IIdentity Identity { get; }
C#
public virtual System.Security.Principal.IIdentity? Identity { get; }

Property Value

The primary claims identity associated with this claims principal.

Implements

Remarks

By default, the framework prioritizes identities of type WindowsIdentity when returning the identity. The first WindowsIdentity found in the Identities collection is returned. If there is no WindowsIdentity in the collection, the first identity assignable from ClaimsIdentity is returned. If there is no ClaimsIdentity, null is returned. If the Identities collection is empty, an ArgumentNullException is thrown.

You can change the default behavior by setting the PrimaryIdentitySelector property to specify a delegate to be called to determine the identity.

Applies to

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, 10
.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

See also