SecurityCallContext.IsCallerInRole(String) Metod
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Verifierar att direktuppringaren är medlem i den angivna rollen.
public:
bool IsCallerInRole(System::String ^ role);
public bool IsCallerInRole(string role);
member this.IsCallerInRole : string -> bool
Public Function IsCallerInRole (role As String) As Boolean
Parametrar
- role
- String
Den angivna rollen.
Returer
trueom direktuppringaren är medlem i den angivna rollen; annars . false
Exempel
I följande kodexempel visas hur den här metoden används för att avgöra om anroparen för en ServicedComponent metod har en angiven roll.
// 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