本文整理汇总了VB.NET中System.Security.Policy.IApplicationTrustManager接口的典型用法代码示例。如果您正苦于以下问题:VB.NET IApplicationTrustManager接口的具体用法?VB.NET IApplicationTrustManager怎么用?VB.NET IApplicationTrustManager使用的例子?那么恭喜您, 这里精选的接口代码示例或许可以为您提供帮助。
在下文中一共展示了IApplicationTrustManager接口的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: MyTrustManager
' To use the custom trust manager MyTrustManager, compile it into CustomTrustManager.dll,
' place that assembly in the GAC, and put the following elements in
' an ApplicationTrust.config file in the config folder in the Microsoft .NET framework
' installation folder.
'<?xml version="1.0" encoding="utf-8" ?>
' <ApplicationEntries />
' <IApplicationTrustManager class="MyNamespace.MyTrustManager, CustomTrustManager, Version=1.0.0.3, Culture=neutral, PublicKeyToken=5659fc598c2a503e"/>
Imports System.Security
Imports System.Security.Policy
Imports System.Windows.Forms
Public Class MyTrustManager
Implements IApplicationTrustManager
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
Public Function ToXml() As SecurityElement Implements IApplicationTrustManager.ToXml
Dim se As New SecurityElement("IApplicationTrustManager")
se.AddAttribute("class", GetType(MyTrustManager).AssemblyQualifiedName)
Return se
End Function 'ToXml
Public Sub FromXml(ByVal se As SecurityElement) Implements IApplicationTrustManager.FromXml
If se.Tag <> "IApplicationTrustManager" OrElse _
CStr(se.Attributes("class")) <> GetType(MyTrustManager).AssemblyQualifiedName Then
Throw New ArgumentException("Invalid tag")
End If
End Sub
End Class