SecurityCallContext.IsCallerInRole(String) 方法

定义

验证直接调用方是指定的角色的成员。Verifies that the direct caller is a member of the specified role.

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

指定的角色。The specified role.

返回

Boolean

如果直接调用方是指定的角色的成员,则为 true;否则为 falsetrue if the direct caller is a member of the specified role; otherwise, false.

示例

下面的代码示例演示如何使用此方法来确定方法的调用方 ServicedComponent 是否在指定的角色中。The following code example demonstrates the use of this method to determine if the caller of a ServicedComponent method is in a specified role.

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

适用于