Share via


SecurityCallContext.IsCallerInRole(String) メソッド

定義

直接の呼び出し元が、指定されたロールのメンバーかどうかを検査します。

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

パラメーター

role
String

指定されたロール。

戻り値

直接の呼び出し元が、指定されたロールのメンバーである場合は true、それ以外の場合は false

次のコード例は、このメソッドを使用して、メソッドの ServicedComponent 呼び出し元が指定されたロールにあるかどうかを判断する方法を示しています。

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

適用対象