Este artigo foi traduzido por máquina. Para visualizar o arquivo em inglês, marque a caixa de seleção Inglês. Você também pode exibir o texto Em inglês em uma janela pop-up, movendo o ponteiro do mouse sobre o texto.
Tradução
Inglês

Método WindowsPrincipal.IsInRole (String)

 

Determina se a entidade de segurança atual pertence ao grupo de usuários do Windows com o nome especificado.

Namespace:   System.Security.Principal
Assembly:  mscorlib (em mscorlib.dll)

[SecurityPermissionAttribute(SecurityAction.Demand, ControlPrincipal = true)]
public override bool IsInRole(
	string role
)

Parâmetros

role
Type: System.String

O nome do grupo de usuários do Windows para o qual verificar a associação.

Valor Retornado

Type: System.Boolean

true se a entidade de segurança atual for membro do grupo de usuários do Windows especificado; caso contrário, false.

When testing for newly created role information, such as a new user or a new group, it is important to log out and log in to force the propagation of role information within the domain. Not doing so can cause the Overload:System.Security.Principal.WindowsPrincipal.IsInRole test to return false. This method is not supported on Windows 98 or Windows Millennium Edition.

For performance reasons, the M:System.Security.Principal.WindowsPrincipal.IsInRole(System.Security.Principal.SecurityIdentifier) overload is recommended as the preferable overload for determining the user's role.

System_CAPS_noteObservação

In Windows Vista, User Account Control (UAC) determines the privileges of a user. If you are a member of the Built-in Administrators group, you are assigned two run-time access tokens: a standard user access token and an administrator access token. By default, you are in the standard user role. When you attempt to perform a task that requires administrative privileges, you can dynamically elevate your role by using the Consent dialog box. The code that executes the Overload:System.Security.Principal.WindowsPrincipal.IsInRole method does not display the Consent dialog box. The code returns false if you are in the standard user role, even if you are in the Built-in Administrators group. You can elevate your privileges before you execute the code by right-clicking the application icon and indicating that you want to run as an administrator.

For built-in roles, the role string should be in the form "BUILTIN\RoleNameHere". For example, to test for membership in the Windows administrator role, the string representing the role should be "BUILTIN\Administrators". Note that the backslash might need to be escaped. The following table lists the built-in roles.

System_CAPS_noteObservação

The spelling for the BUILTIN roles in string format differs from the spelling used in the T:System.Security.Principal.WindowsBuiltInRole enumeration. For example, the spelling for an administrator in the enumeration is "Administrator", not "Administrators". When using this overload, use the spelling for the role from the following table.

Built-in local groups

BUILTIN\Administrators

BUILTIN\Users

BUILTIN\Guests

BUILTIN\Account Operators

BUILTIN\Server Operators

BUILTIN\Print Operators

BUILTIN\Backup Operators

BUILTIN\Replicator

For machine-specific roles, the role string should be in the form "MachineName\RoleNameHere".

For domain-specific roles, the role string should be in the form "DomainName\RoleNameHere"; for example, "SomeDomain\Domain Users".

System_CAPS_noteObservação

In the .NET Framework version 1.0, the role parameter is case-sensitive. In the .NET Framework version 1.1 and later, the role parameter is case-insensitive.

The following code example demonstrates the use of the M:System.Security.Principal.WindowsPrincipal.IsInRole(System.String) method.

The strings BUILTIN\Administrators and BUILTIN\Users are used to determine whether the current principal is an administrator or a user. For the full code example, see the M:System.Security.Principal.WindowsPrincipal.IsInRole(System.Int32) method.

// Get the role using the string value of the role.
Console.WriteLine("{0}? {1}.", "Administrators",
    myPrincipal.IsInRole("BUILTIN\\" + "Administrators"));
Console.WriteLine("{0}? {1}.", "Users",
    myPrincipal.IsInRole("BUILTIN\\" + "Users"));

SecurityPermission

for the ability to manipulate the principal object. Associated enumeration: F:System.Security.Permissions.SecurityPermissionFlag.ControlPrincipal

.NET Framework
Disponível desde 1.1
Retornar ao início
Mostrar: