SecurityCallContext.IsCallerInRole(String) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
驗證直接呼叫者是否屬於指定角色。
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