GenericPrincipal.IsInRole(String) GenericPrincipal.IsInRole(String) GenericPrincipal.IsInRole(String) GenericPrincipal.IsInRole(String) Method

定义

确定当前 GenericPrincipal 是否属于指定的角色。Determines whether the current GenericPrincipal belongs to the specified role.

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

参数

role
String String String String

要检查其成员资格的角色的名称。The name of the role for which to check membership.

返回

如果当前 GenericPrincipal 是指定角色的成员,则为 true;否则为 falsetrue if the current GenericPrincipal is a member of the specified role; otherwise, false.

示例

下面的代码演示如何使用IsInRole方法。The following code shows the use of the IsInRole method. 此代码示例是为提供一个更大示例的一部分GenericPrincipal类。This code example is part of a larger example provided for the GenericPrincipal class.

if ( genericPrincipal->IsInRole( L"NetworkUser" ) )
{
   Console::WriteLine( L"User belongs to the NetworkUser role." );
}
if (genericPrincipal.IsInRole("NetworkUser"))
{
    Console.WriteLine("User belongs to the NetworkUser role.");
}
If (genericPrincipal.IsInRole("NetworkUser")) Then
    WriteLine("User belongs to the NetworkUser role.")
End If

适用于