AppDomainManager AppDomainManager AppDomainManager AppDomainManager Class

定义

提供非托管宿主的托管等效项。Provides a managed equivalent of an unmanaged host.

public ref class AppDomainManager : MarshalByRefObject
[System.Runtime.InteropServices.ComVisible(true)]
[System.Security.SecurityCritical]
public class AppDomainManager : MarshalByRefObject
type AppDomainManager = class
    inherit MarshalByRefObject
Public Class AppDomainManager
Inherits MarshalByRefObject
继承
AppDomainManagerAppDomainManagerAppDomainManagerAppDomainManager
属性

示例

下面的示例演示的AppDomainManager实现非常简单。The following example shows a very simple implementation of AppDomainManager.

// To replace the default AppDomainManager, identify  the 
// replacement assembly and replacement type in the 
// APPDOMAIN_MANAGER_ASM and APPDOMAIN_MANAGER_TYPE  
// environment variables. For example:
// set APPDOMAIN_MANAGER_TYPE=library.TestAppDomainManager
// set APPDOMAIN_MANAGER_ASM=library, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f1368f7b12a08d72

using System;
using System.Collections;
using System.Net;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using System.Security.Policy;
using System.Security.Principal;
using System.Threading;
using System.Runtime.InteropServices;

[assembly: System.Security.AllowPartiallyTrustedCallersAttribute()]

namespace MyNamespace
{
    [GuidAttribute("F4D15099-3407-4A7E-A607-DEA440CF3891")]
    [SecurityPermissionAttribute(SecurityAction.LinkDemand, 
        Flags = SecurityPermissionFlag.Infrastructure)]
    [SecurityPermissionAttribute(SecurityAction.InheritanceDemand, 
        Flags = SecurityPermissionFlag.Infrastructure)]
    public class MyAppDomainManager : AppDomainManager
    {
        private HostSecurityManager mySecurityManager = null;

        public MyAppDomainManager()
        {
            Console.WriteLine(" My AppDomain Manager ");
            mySecurityManager = AppDomain.CurrentDomain.CreateInstanceAndUnwrap(
                "CustomSecurityManager, Version=1.0.0.3, Culture=neutral, " +
                "PublicKeyToken=5659fc598c2a503e", 
                "MyNamespace.MySecurityManager") as HostSecurityManager;
            Console.WriteLine(" Custom Security Manager Created.");
        }

        public override void InitializeNewDomain(AppDomainSetup appDomainInfo)
        {
            Console.Write("Initialize new domain called:  ");
            Console.WriteLine(AppDomain.CurrentDomain.FriendlyName);
            InitializationFlags = 
                AppDomainManagerInitializationOptions.RegisterWithHost;
        }

        public override HostSecurityManager HostSecurityManager
        {
            get
            {
                return mySecurityManager;
            }
        }
    }
}
' To replace the default AppDomainManager, identify  the 
' replacement assembly and replacement type in the 
' APPDOMAIN_MANAGER_ASM and APPDOMAIN_MANAGER_TYPE  
' environment variables. For example:
' set APPDOMAIN_MANAGER_TYPE=library.TestAppDomainManager
' set APPDOMAIN_MANAGER_ASM=library, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f1368f7b12a08d72
Imports System.Collections
Imports System.Net
Imports System.Reflection
Imports System.Security
Imports System.Security.Permissions
Imports System.Security.Policy
Imports System.Security.Principal
Imports System.Threading
Imports System.Runtime.InteropServices

<assembly: System.Security.AllowPartiallyTrustedCallersAttribute()>
<SecurityPermissionAttribute(SecurityAction.LinkDemand, _
    Flags:=SecurityPermissionFlag.Infrastructure)> _
<SecurityPermissionAttribute(SecurityAction.InheritanceDemand, _
    Flags:=SecurityPermissionFlag.Infrastructure)> _
<GuidAttribute("F4D15099-3407-4A7E-A607-DEA440CF3891")> _
Public Class MyAppDomainManager
    Inherits AppDomainManager
    Private mySecurityManager As HostSecurityManager = Nothing
    
    Public Sub New() 
        Console.WriteLine(" My AppDomain Manager ")
        mySecurityManager = AppDomain.CurrentDomain.CreateInstanceAndUnwrap( _
            "CustomSecurityManager, Version=1.0.0.3, Culture=neutral, " & _
            "PublicKeyToken=5659fc598c2a503e", "MyNamespace.MySecurityManager")
        Console.WriteLine(" Custom Security Manager Created.")    
    End Sub 'New
    
    Public Overrides Sub InitializeNewDomain(ByVal appDomainInfo _
        As AppDomainSetup) 
        Console.Write("Initialize new domain called:  ")
        Console.WriteLine(AppDomain.CurrentDomain.FriendlyName)
        InitializationFlags = _
            AppDomainManagerInitializationOptions.RegisterWithHost   
    End Sub 'InitializeNewDomain

    Public Overrides ReadOnly Property HostSecurityManager() _
        As HostSecurityManager 
        Get
            Return mySecurityManager
        End Get
    End Property
End Class 'MyAppDomainManager 

注解

重要

不要使用AppDomainManager在 ASP.NET 中配置应用程序域。Do not use AppDomainManager to configure an application domain in ASP.NET. 在 ASP.NET 中, 必须由主机处理配置。In ASP.NET, configuration must be handled by the host.

通过实现AppDomainManager类, 宿主应用程序可以参与创建新的应用程序域。Implementing the AppDomainManager class enables a hosting application to participate in the creation of new application domains. 若要替换默认AppDomainManager值, 请在 APPDOMAIN_MANAGER_ASM 和 APPDOMAIN_MANAGER_TYPE 环境AppDomainManager <变量中标识替换项的程序集和类型, 或使用 b l y > 和y p e 配置文件中的元素 >。 <To replace the default AppDomainManager, identify the assembly and type of the replacement AppDomainManager in the APPDOMAIN_MANAGER_ASM and APPDOMAIN_MANAGER_TYPE environment variables, or use the <appDomainManagerAssembly> and <appDomainManagerType> elements in your configuration file. 该程序集必须是完全受信任的, 并且包含在全局程序集缓存或启动应用程序的目录中。The assembly must be fully trusted and be contained in the global assembly cache or the directory of the starting application. 在环境变量中必须完全限定类型名称和程序集名称。The type and assembly names must be fully qualified in the environment variables. 例如:For example:

set APPDOMAIN_MANAGER_TYPE=MyNamespace.TestAppDomainManager

set APPDOMAIN_MANAGER_ASM=customappDomainmanager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f1368f7b12a08d72

重要

如果包含的AppDomainManager子类的程序集依赖于用条件AllowPartiallyTrustedCallersAttribute (APTCA) 特性标记的程序集, 则必须将这些程序集包含在传递到的PartialTrustVisibleAssemblies AppDomainSetup属性的列表中。使用创建应用程序域。If the assembly that contains your subclass of AppDomainManager depends on assemblies that are marked with the conditional AllowPartiallyTrustedCallersAttribute (APTCA) attribute, you must include those assemblies in the list that you pass to the PartialTrustVisibleAssemblies property of the AppDomainSetup you use to create application domains. 否则, 将禁用用条件 APTCA 特性标记的程序集。Otherwise, the assemblies that are marked with the conditional APTCA attribute will be disabled.

AppDomainManager是非托管宿主的托管等效项。The AppDomainManager is the managed equivalent of the unmanaged host. 对象参与在进程中创建新的应用程序域, 并可以在运行其他托管AppDomain代码之前自定义新的。 AppDomainManagerAn AppDomainManager object participates in the creation of new application domains in a process and can customize the new AppDomain before other managed code runs. AppDomainManager可以提供参与公共语言运行时执行的其他方面的主机管理器。The AppDomainManager can also supply host managers that participate in other aspects of common language runtime execution. 例如, AppDomainManager可以HostSecurityManager标识参与应用程序域的安全决策的对象。For example, an AppDomainManager can identify a HostSecurityManager object that participates in the security decisions of the application domain.

备注

FullTrust授予的程序集 (例如全局程序集缓存中的程序集fullTrustAssemblies或在AppDomain.CreateDomain(String, Evidence, AppDomainSetup, PermissionSet, StrongName[])方法中标识为的程序AppDomainManager集) InitializeNewDomain可以在构造函数和方法中加载。Only assemblies granted FullTrust, such as assemblies in the global assembly cache or identified as fullTrustAssemblies in the AppDomain.CreateDomain(String, Evidence, AppDomainSetup, PermissionSet, StrongName[]) method can be loaded in the AppDomainManager constructor and the InitializeNewDomain method.

备注

此类包含类级别的链接要求和继承要求。This class contains a link demand and an inheritance demand at the class level. 当直接调用方或派生类没有基础结构权限时,将引发。SecurityExceptionA SecurityException is thrown when either the immediate caller or the derived class does not have infrastructure permission. 有关安全要求的详细信息, 请参阅链接要求继承要求For details about security demands, see Link Demands and Inheritance Demands.

构造函数

AppDomainManager() AppDomainManager() AppDomainManager() AppDomainManager()

初始化 AppDomainManager 类的新实例。Initializes a new instance of the AppDomainManager class.

属性

ApplicationActivator ApplicationActivator ApplicationActivator ApplicationActivator

获取应用程序激活器,该激活器用于激活相应域中的外接程序和基于清单的应用程序。Gets the application activator that handles the activation of add-ins and manifest-based applications for the domain.

EntryAssembly EntryAssembly EntryAssembly EntryAssembly

获取应用程序的入口程序集。Gets the entry assembly for an application.

HostExecutionContextManager HostExecutionContextManager HostExecutionContextManager HostExecutionContextManager

获取宿主执行上下文管理器,该管理器对执行上下文的流进行管理。Gets the host execution context manager that manages the flow of the execution context.

HostSecurityManager HostSecurityManager HostSecurityManager HostSecurityManager

获取宿主安全管理器,该管理器参与应用程序域的安全决策。Gets the host security manager that participates in security decisions for the application domain.

InitializationFlags InitializationFlags InitializationFlags InitializationFlags

获取自定义应用程序域管理器的初始化标志。Gets the initialization flags for custom application domain managers.

方法

CheckSecuritySettings(SecurityState) CheckSecuritySettings(SecurityState) CheckSecuritySettings(SecurityState) CheckSecuritySettings(SecurityState)

指示是否允许在应用程序域中执行指定的操作。Indicates whether the specified operation is allowed in the application domain.

CreateDomain(String, Evidence, AppDomainSetup) CreateDomain(String, Evidence, AppDomainSetup) CreateDomain(String, Evidence, AppDomainSetup) CreateDomain(String, Evidence, AppDomainSetup)

返回新的或现有的应用程序域。Returns a new or existing application domain.

CreateDomainHelper(String, Evidence, AppDomainSetup) CreateDomainHelper(String, Evidence, AppDomainSetup) CreateDomainHelper(String, Evidence, AppDomainSetup) CreateDomainHelper(String, Evidence, AppDomainSetup)

提供帮助器方法以创建一个应用程序域。Provides a helper method to create an application domain.

CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetLifetimeService() GetLifetimeService() GetLifetimeService() GetLifetimeService()

检索控制此实例的生存期策略的当前生存期服务对象。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService()

获取生存期服务对象来控制此实例的生存期策略。Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
InitializeNewDomain(AppDomainSetup) InitializeNewDomain(AppDomainSetup) InitializeNewDomain(AppDomainSetup) InitializeNewDomain(AppDomainSetup)

初始化新应用程序域。Initializes the new application domain.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
ToString() ToString() ToString() ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)

安全性

SecurityCriticalAttribute
需要对直接调用方的完全信任。Requires full trust for the immediate caller. 部分受信任的或透明的代码不能使用此成员。This member cannot be used by partially trusted or transparent code.

InheritanceDemand
用于将可执行代码插入到公共语言运行时承载基础结构的派生类。for derived classes to plug executable code into the common language runtime hosting infrastructure. 关联枚举:InfrastructureAssociated enumeration: Infrastructure.

适用于