Share via


SecurityCallContext.IsCallerInRole(String) Método

Definición

Comprueba si el llamador directo actual es un miembro del rol especificado.

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

Rol especificado.

Devoluciones

true si el llamador directo es un miembro del rol especificado; en caso contrario, false.

Ejemplos

En el ejemplo de código siguiente se muestra el uso de este método para determinar si el autor de la llamada de un ServicedComponent método está en un rol especificado.

// 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

Se aplica a