AppDomainManager 類別

定義

提供 Unmanaged 主機的 Managed 對等項目。Provides a managed equivalent of an unmanaged host.

public ref class AppDomainManager : MarshalByRefObject
[System.Runtime.InteropServices.ComVisible(true)]
public class AppDomainManager : MarshalByRefObject
[System.Runtime.InteropServices.ComVisible(true)]
[System.Security.SecurityCritical]
public class AppDomainManager : MarshalByRefObject
[<System.Runtime.InteropServices.ComVisible(true)>]
type AppDomainManager = class
    inherit MarshalByRefObject
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Security.SecurityCritical>]
type AppDomainManager = class
    inherit MarshalByRefObject
Public Class AppDomainManager
Inherits MarshalByRefObject
繼承
AppDomainManager
屬性

範例

下列範例顯示非常簡單的執行 AppDomainManagerThe 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
    
    Public Overrides Sub InitializeNewDomain(ByVal appDomainInfo _
        As AppDomainSetup) 
        Console.Write("Initialize new domain called:  ")
        Console.WriteLine(AppDomain.CurrentDomain.FriendlyName)
        InitializationFlags = _
            AppDomainManagerInitializationOptions.RegisterWithHost   
    End Sub

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

備註

重要

請勿使用 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 ,請 AppDomainManager 在 APPDOMAIN_MANAGER_ASM 和 APPDOMAIN_MANAGER_TYPE 環境變數中找出取代的元件和類型,或使用 <appDomainManagerAssembly> <appDomainManagerType> 設定檔中的和元素。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. AppDomainManager物件會參與在進程中建立新的應用程式域,而且可以在 AppDomain 其他 managed 程式碼執行之前自訂新的應用程式域。An 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也可以提供參與 common language runtime 執行其他層面的主機管理員。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[]) 可以載入至函式 AppDomainManagerInitializeNewDomain 方法中。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. SecurityException當立即呼叫端或衍生類別沒有基礎結構許可權時,就會擲回。A 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 類別的新執行個體。Initializes a new instance of the AppDomainManager class.

屬性

ApplicationActivator

取得應用程式啟動項,這個應用程式啟動項會處理定義域中增益集和資訊清單架構應用程式的啟動。Gets the application activator that handles the activation of add-ins and manifest-based applications for the domain.

EntryAssembly

取得應用程式的項目組件。Gets the entry assembly for an application.

HostExecutionContextManager

取得管理執行內容流程的主機執行內容管理員。Gets the host execution context manager that manages the flow of the execution context.

HostSecurityManager

取得參與應用程式定義域安全性決策的主機安全性管理員。Gets the host security manager that participates in security decisions for the application domain.

InitializationFlags

取得自訂應用程式定義域管理員的初始設定旗標。Gets the initialization flags for custom application domain managers.

方法

CheckSecuritySettings(SecurityState)

表示應用程式定義域中是否允許指定的作業。Indicates whether the specified operation is allowed in the application domain.

CreateDomain(String, Evidence, AppDomainSetup)

傳回新的或現有的應用程式定義域。Returns a new or existing application domain.

CreateDomainHelper(String, Evidence, AppDomainSetup)

提供建立應用程式定義域的 Helper 方法。Provides a helper method to create an application domain.

CreateObjRef(Type)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(繼承來源 MarshalByRefObject)
Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetLifetimeService()

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(繼承來源 MarshalByRefObject)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
InitializeLifetimeService()

取得存留期服務物件,以控制這個執行個體的存留期原則。Obtains a lifetime service object to control the lifetime policy for this instance.

(繼承來源 MarshalByRefObject)
InitializeNewDomain(AppDomainSetup)

初始化新應用程式定義域。Initializes the new application domain.

MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
MemberwiseClone(Boolean)

建立目前 MarshalByRefObject 物件的淺層複本。Creates a shallow copy of the current MarshalByRefObject object.

(繼承來源 MarshalByRefObject)
ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

適用於