IApplicationTrustManager.DetermineApplicationTrust 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
判斷是否應執行應用程式,以及應授與該應用程式的使用權限集合。
public:
System::Security::Policy::ApplicationTrust ^ DetermineApplicationTrust(ActivationContext ^ activationContext, System::Security::Policy::TrustManagerContext ^ context);
public System.Security.Policy.ApplicationTrust DetermineApplicationTrust (ActivationContext activationContext, System.Security.Policy.TrustManagerContext context);
abstract member DetermineApplicationTrust : ActivationContext * System.Security.Policy.TrustManagerContext -> System.Security.Policy.ApplicationTrust
Public Function DetermineApplicationTrust (activationContext As ActivationContext, context As TrustManagerContext) As ApplicationTrust
參數
- activationContext
- ActivationContext
應用程式的啟用內容。
- context
- TrustManagerContext
此應用程式的信任管理員內容。
傳回
包含應用程式相關安全性決策的物件。
範例
下列範例示範自訂信任管理員的 方法實 DetermineApplicationTrust 作。 此程式碼範例是提供給 介面之較大範例的 IApplicationTrustManager 一部分。
public ApplicationTrust DetermineApplicationTrust(ActivationContext appContext, TrustManagerContext context)
{
ApplicationTrust trust = new ApplicationTrust(appContext.Identity);
trust.IsApplicationTrustedToRun = false;
ApplicationSecurityInfo asi = new ApplicationSecurityInfo(appContext);
trust.DefaultGrantSet = new PolicyStatement(asi.DefaultRequestSet, PolicyStatementAttribute.Nothing);
if (context.UIContext == TrustManagerUIContext.Run)
{
string message = "Do you want to run " + asi.ApplicationId.Name + " ?";
string caption = "MyTrustManager";
MessageBoxButtons buttons = MessageBoxButtons.YesNo;
DialogResult result;
// Displays the MessageBox.
result = MessageBox.Show(message, caption, buttons);
if (result == DialogResult.Yes)
{
trust.IsApplicationTrustedToRun = true;
if (context != null)
trust.Persist = context.Persist;
else
trust.Persist = false;
}
}
return trust;
}
Public Function DetermineApplicationTrust(ByVal appContext As ActivationContext, ByVal context As TrustManagerContext) As ApplicationTrust Implements IApplicationTrustManager.DetermineApplicationTrust
Dim trust As New ApplicationTrust(appContext.Identity)
trust.IsApplicationTrustedToRun = False
Dim asi As New ApplicationSecurityInfo(appContext)
trust.DefaultGrantSet = New PolicyStatement(asi.DefaultRequestSet, _
PolicyStatementAttribute.Nothing)
If context.UIContext = TrustManagerUIContext.Run Then
Dim message As String = "Do you want to run " + asi.ApplicationId.Name + " ?"
Dim caption As String = "MyTrustManager"
Dim buttons As MessageBoxButtons = MessageBoxButtons.YesNo
Dim result As DialogResult
' Displays the MessageBox.
result = MessageBox.Show(message, caption, buttons)
If result = DialogResult.Yes Then
trust.IsApplicationTrustedToRun = True
If Not (context Is Nothing) Then
trust.Persist = context.Persist
Else
trust.Persist = False
End If
End If
End If
Return trust
End Function 'DetermineApplicationTrust
備註
主機 DetermineApplicationTrust 會呼叫 方法,以判斷是否應該執行應用程式,以及應該授與哪一組許可權。 DetermineApplicationTrustApplicationTrust傳回 物件,其 DefaultGrantSet 屬性包含許可權集合,表示要授與應用程式內容內執行之每個元件的許可權。 授與的許可權不適用於全域組件快取中的元件。 物件 ApplicationTrust 也有 IsApplicationTrustedToRun 信任管理員設定的屬性,以指出是否應該信任應用程式。 如果信任管理員指出應用程式可以信任,主機會啟動應用程式,並將集合中 ApplicationTrust 提供的許可權集授與其元件。