HostSecurityManager.DetermineApplicationTrust 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
決定是否應該執行應用程式。
public:
virtual System::Security::Policy::ApplicationTrust ^ DetermineApplicationTrust(System::Security::Policy::Evidence ^ applicationEvidence, System::Security::Policy::Evidence ^ activatorEvidence, System::Security::Policy::TrustManagerContext ^ context);
public virtual System.Security.Policy.ApplicationTrust DetermineApplicationTrust (System.Security.Policy.Evidence applicationEvidence, System.Security.Policy.Evidence activatorEvidence, System.Security.Policy.TrustManagerContext context);
[System.Security.SecurityCritical]
public virtual System.Security.Policy.ApplicationTrust DetermineApplicationTrust (System.Security.Policy.Evidence applicationEvidence, System.Security.Policy.Evidence activatorEvidence, System.Security.Policy.TrustManagerContext context);
abstract member DetermineApplicationTrust : System.Security.Policy.Evidence * System.Security.Policy.Evidence * System.Security.Policy.TrustManagerContext -> System.Security.Policy.ApplicationTrust
override this.DetermineApplicationTrust : System.Security.Policy.Evidence * System.Security.Policy.Evidence * System.Security.Policy.TrustManagerContext -> System.Security.Policy.ApplicationTrust
[<System.Security.SecurityCritical>]
abstract member DetermineApplicationTrust : System.Security.Policy.Evidence * System.Security.Policy.Evidence * System.Security.Policy.TrustManagerContext -> System.Security.Policy.ApplicationTrust
override this.DetermineApplicationTrust : System.Security.Policy.Evidence * System.Security.Policy.Evidence * System.Security.Policy.TrustManagerContext -> System.Security.Policy.ApplicationTrust
Public Overridable Function DetermineApplicationTrust (applicationEvidence As Evidence, activatorEvidence As Evidence, context As TrustManagerContext) As ApplicationTrust
參數
- applicationEvidence
- Evidence
要啟動之應用程式的辨識項。
- activatorEvidence
- Evidence
或者,啟動中應用程式定義域的辨識項。
- context
- TrustManagerContext
信任內容。
傳回
包含應用程式相關信任資訊的物件。
- 屬性
例外狀況
applicationEvidence
為 null
。
ApplicationTrust 授權集不包含 ActivationContext 所指定的最小要求集。
範例
下列範例示範如何覆寫 DetermineApplicationTrust 自定義主機安全性管理員的方法。 這個範例是提供給 類別之較大範例的 HostSecurityManager 一部分。
[SecurityPermissionAttribute(SecurityAction.Demand, Execution = true)]
[SecurityPermissionAttribute(SecurityAction.Assert, Unrestricted = true)]
public override ApplicationTrust DetermineApplicationTrust(Evidence applicationEvidence, Evidence activatorEvidence, TrustManagerContext context)
{
if (applicationEvidence == null)
throw new ArgumentNullException("applicationEvidence");
// Get the activation context from the application evidence.
// This HostSecurityManager does not examine the activator evidence
// nor is it concerned with the TrustManagerContext;
// it simply grants the requested grant in the application manifest.
IEnumerator enumerator = applicationEvidence.GetHostEnumerator();
ActivationArguments activationArgs = null;
while (enumerator.MoveNext())
{
activationArgs = enumerator.Current as ActivationArguments;
if (activationArgs != null)
break;
}
if (activationArgs == null)
return null;
ActivationContext activationContext = activationArgs.ActivationContext;
if (activationContext == null)
return null;
ApplicationTrust trust = new ApplicationTrust(activationContext.Identity);
ApplicationSecurityInfo asi = new ApplicationSecurityInfo(activationContext);
trust.DefaultGrantSet = new PolicyStatement(asi.DefaultRequestSet, PolicyStatementAttribute.Nothing);
trust.IsApplicationTrustedToRun = true;
return trust;
}
<SecurityPermissionAttribute(SecurityAction.Demand, Execution:=True), SecurityPermissionAttribute(SecurityAction.Assert, Unrestricted:=True)> _
Public Overrides Function DetermineApplicationTrust(ByVal applicationEvidence As Evidence, ByVal activatorEvidence As Evidence, ByVal context As TrustManagerContext) As ApplicationTrust
If applicationEvidence Is Nothing Then
Throw New ArgumentNullException("applicationEvidence")
End If
' Get the activation context from the application evidence.
' This HostSecurityManager does not examine the activator evidence
' nor is it concerned with the TrustManagerContext;
' it simply grants the requested grant in the application manifest.
Dim enumerator As IEnumerator = applicationEvidence.GetHostEnumerator()
Dim activationArgs As ActivationArguments = Nothing
While enumerator.MoveNext()
activationArgs = enumerator.Current '
If Not (activationArgs Is Nothing) Then
Exit While
End If
End While
If activationArgs Is Nothing Then
Return Nothing
End If
Dim activationContext As ActivationContext = activationArgs.ActivationContext
If activationContext Is Nothing Then
Return Nothing
End If
Dim trust As New ApplicationTrust(activationContext.Identity)
Dim asi As New ApplicationSecurityInfo(activationContext)
trust.DefaultGrantSet = New PolicyStatement(asi.DefaultRequestSet, PolicyStatementAttribute.Nothing)
trust.IsApplicationTrustedToRun = True
Return trust
End Function 'DetermineApplicationTrust
End Class
備註
這個方法可由衍生類別覆寫。 基底實作會呼叫應用程式安全性管理員,以判斷是否應該執行應用程式。
基底實作不會使用啟動器辨識項。 不過,覆寫的實作可以使用啟動程式辨識項來判斷嘗試啟動應用程式之應用程式域的安全性辨識項。