ClaimsPrincipal.IsInRole(String) 方法

定义

返回一个值,该值表示此声明主体代表的实体(用户)是否属于指定角色。Returns a value that indicates whether the entity (user) represented by this claims principal is in the specified role.

public:
 virtual bool IsInRole(System::String ^ role);
public virtual bool IsInRole (string role);
abstract member IsInRole : string -> bool
override this.IsInRole : string -> bool
Public Overridable Function IsInRole (role As String) As Boolean

参数

role
String

要检查的角色。The role for which to check.

返回

Boolean

如果声明主体属于指定角色,则为 true;否则为 falsetrue if claims principal is in the specified role; otherwise, false.

实现

注解

IsInRole方法检查此声明主体拥有的标识是否包含类型的声明, ClaimsIdentity.RoleClaimType 其中声明的值等于参数指定的值 roleThe 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.

备注

每个 ClaimsIdentity 都有其自己的表示角色的声明类型的定义。Each ClaimsIdentity has its own definition of the claim type that represents a role. 可以通过属性访问和设置此声明类型 ClaimsIdentity.RoleClaimTypeThis claim type can be accessed and set through the ClaimsIdentity.RoleClaimType property.

适用于