SecurityCallContext.DirectCaller 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得 SecurityIdentity 物件,該物件描述這個方法的直接呼叫端。
public:
property System::EnterpriseServices::SecurityIdentity ^ DirectCaller { System::EnterpriseServices::SecurityIdentity ^ get(); };
public System.EnterpriseServices.SecurityIdentity DirectCaller { get; }
member this.DirectCaller : System.EnterpriseServices.SecurityIdentity
Public ReadOnly Property DirectCaller As SecurityIdentity
屬性值
範例
下列程式代碼範例示範如何使用此方法來檢查方法直接 ServicedComponent 呼叫者的身分識別。
// Get the employee's salary. Only the employee and managers can do this.
double GetSalary()
{
if ( SecurityCallContext::CurrentCall->DirectCaller->AccountName == accountName || SecurityCallContext::CurrentCall->IsCallerInRole( "Manager" ) )
{
return (salary);
}
else
{
throw gcnew UnauthorizedAccessException;
}
}
// Get the employee's salary. Only the employee and managers can do this.
public double GetSalary ()
{
if ( SecurityCallContext.CurrentCall.DirectCaller.AccountName == accountName ||
SecurityCallContext.CurrentCall.IsCallerInRole("Manager") )
{
return(salary);
}
else
{
throw new UnauthorizedAccessException();
}
}
' Get the employee's salary. Only the employee and managers can do this.
Public Function GetSalary() As Double
If SecurityCallContext.CurrentCall.DirectCaller.AccountName = accountName OrElse SecurityCallContext.CurrentCall.IsCallerInRole("Manager") Then
Return salary
Else
Throw New UnauthorizedAccessException()
End If
End Function 'GetSalary