Share via


SecurityCallContext.IsCallerInRole(String) Método

Definição

Verifica se o chamador direto é um membro da função especificada.

public:
 bool IsCallerInRole(System::String ^ role);
public bool IsCallerInRole (string role);
member this.IsCallerInRole : string -> bool
Public Function IsCallerInRole (role As String) As Boolean

Parâmetros

role
String

A função especificada.

Retornos

true se o chamador direto for membro da função especificada; caso contrário, false.

Exemplos

O exemplo de código a seguir demonstra o uso desse método para determinar se o chamador de um ServicedComponent método está em uma função especificada.

// Set the employee's salary. Only managers can do this.
void SetSalary( double ammount )
{
   if ( SecurityCallContext::CurrentCall->IsCallerInRole( "Manager" ) )
   {
      salary = ammount;
   }
   else
   {
      throw gcnew UnauthorizedAccessException;
   }
}
// Set the employee's salary. Only managers can do this.
public void SetSalary (double ammount)
{
    if (SecurityCallContext.CurrentCall.IsCallerInRole("Manager"))
    {
        salary = ammount;
    }
    else
    {
        throw new UnauthorizedAccessException();
    }
}
' Set the employee's salary. Only managers can do this.
Public Sub SetSalary(ByVal ammount As Double) 
    If SecurityCallContext.CurrentCall.IsCallerInRole("Manager") Then
        salary = ammount
    Else
        Throw New UnauthorizedAccessException()
    End If

End Sub

Aplica-se a