Bagikan melalui


SecurityCallContext.IsCallerInRole(String) Metode

Definisi

Memverifikasi bahwa penelepon langsung adalah anggota peran yang ditentukan.

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

Parameter

role
String

Peran yang ditentukan.

Mengembalikan

true jika penelepon langsung adalah anggota peran yang ditentukan; jika tidak, false.

Contoh

Contoh kode berikut menunjukkan penggunaan metode ini untuk menentukan apakah pemanggil ServicedComponent metode berada dalam peran tertentu.

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

Berlaku untuk