Freigeben über


SecurityCallContext.IsCallerInRole-Methode

Überprüft, ob der direkte Aufrufer ein Member der angegebenen Rolle ist.

Namespace: System.EnterpriseServices
Assembly: System.EnterpriseServices (in system.enterpriseservices.dll)

Syntax

'Declaration
Public Function IsCallerInRole ( _
    role As String _
) As Boolean
'Usage
Dim instance As SecurityCallContext
Dim role As String
Dim returnValue As Boolean

returnValue = instance.IsCallerInRole(role)
public bool IsCallerInRole (
    string role
)
public:
bool IsCallerInRole (
    String^ role
)
public boolean IsCallerInRole (
    String role
)
public function IsCallerInRole (
    role : String
) : boolean

Parameter

  • role
    Die angegebene Rolle.

Rückgabewert

true, wenn der direkte Aufrufer ein Mitglied der angegebenen Rolle ist, andernfalls false.

Beispiel

Im folgenden Codebeispiel wird veranschaulicht, wie diese Methode verwendet wird, um zu bestimmen, ob sich der Aufrufer einer ServicedComponent-Methode in einer angegebenen Rolle befindet.

' 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 'SetSalary
// 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.
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) 
    throws System.UnauthorizedAccessException
{
    if (SecurityCallContext.get_CurrentCall().IsCallerInRole("Manager")) {
        salary = ammount;
    }
    else {
        throw new UnauthorizedAccessException();
    }
} //SetSalary

.NET Framework-Sicherheit

  • Volle Vertrauenswürdigkeit für den unmittelbaren Aufrufer. Dieser Member kann von nur teilweise vertrauenswürdigem Code nicht verwendet werden. Weitere Informationen finden Sie unter .

Plattformen

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

SecurityCallContext-Klasse
SecurityCallContext-Member
System.EnterpriseServices-Namespace