ClaimsPrincipal.IsInRole(String) Method

Definition

Returns a value that indicates whether the entity (user) represented by this claims principal is in the specified role.

C#
public virtual bool IsInRole(string role);

Parameters

role
String

The role for which to check.

Returns

true if claims principal is in the specified role; otherwise, false.

Implements

Remarks

The IsInRole method checks whether an identity that this claims principal possesses contains a claim of type ClaimsIdentity.RoleClaimType where the value of the claim is equal to the value specified by the role parameter.

Note

Each ClaimsIdentity has its own definition of the claim type that represents a role. This claim type can be accessed and set through the ClaimsIdentity.RoleClaimType property.

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