AppDomainSetup.ApplicationBase 屬性

定義

取得或設定包含應用程式的目錄名稱。Gets or sets the name of the directory containing the application.

public:
 property System::String ^ ApplicationBase { System::String ^ get(); void set(System::String ^ value); };
public string ApplicationBase { get; set; }
member this.ApplicationBase : string with get, set
Public Property ApplicationBase As String

屬性值

應用程式基底目錄的名稱。The name of the application base directory.

實作

範例

下列範例示範如何使用ApplicationBase屬性來設定元件載入器開始探查元件的位置,以載入新的應用程式域。The following example demonstrates how to use the ApplicationBase property to set the location where the assembly loader begins probing for assemblies to load into a new application domain.

注意

您必須確定您指定的資料夾已存在。You must ensure that the folder you specify exists.

using namespace System;

int main()
{
    AppDomain^ root = AppDomain::CurrentDomain;

    AppDomainSetup^ setup = gcnew AppDomainSetup();
    setup->ApplicationBase = 
        root->SetupInformation->ApplicationBase + "MyAppSubfolder\\";

    AppDomain^ domain = AppDomain::CreateDomain("MyDomain", nullptr, setup);

    Console::WriteLine("Application base of {0}:\r\n\t{1}", 
        root->FriendlyName, root->SetupInformation->ApplicationBase);
    Console::WriteLine("Application base of {0}:\r\n\t{1}", 
        domain->FriendlyName, domain->SetupInformation->ApplicationBase);

    AppDomain::Unload(domain);
}

/* This example produces output similar to the following:

Application base of MyApp.exe:
        C:\Program Files\MyApp\
Application base of MyDomain:
        C:\Program Files\MyApp\MyAppSubfolder\
 */
using System;

class ADSetupInformation
{
    static void Main()
    {
        AppDomain root = AppDomain.CurrentDomain;

        AppDomainSetup setup = new AppDomainSetup();
        setup.ApplicationBase = 
            root.SetupInformation.ApplicationBase + @"MyAppSubfolder\";

        AppDomain domain = AppDomain.CreateDomain("MyDomain", null, setup);

        Console.WriteLine("Application base of {0}:\r\n\t{1}", 
            root.FriendlyName, root.SetupInformation.ApplicationBase);
        Console.WriteLine("Application base of {0}:\r\n\t{1}", 
            domain.FriendlyName, domain.SetupInformation.ApplicationBase);

        AppDomain.Unload(domain);
    }
}

/* This example produces output similar to the following:

Application base of MyApp.exe:
        C:\Program Files\MyApp\
Application base of MyDomain:
        C:\Program Files\MyApp\MyAppSubfolder\
 */
Class ADSetupInformation

    Shared Sub Main()

        Dim root As AppDomain = AppDomain.CurrentDomain

        Dim setup As New AppDomainSetup()
        setup.ApplicationBase = _
            root.SetupInformation.ApplicationBase & "MyAppSubfolder\"

        Dim domain As AppDomain = AppDomain.CreateDomain("MyDomain", Nothing, setup)

        Console.WriteLine("Application base of {0}:" & vbCrLf & vbTab & "{1}", _
            root.FriendlyName, root.SetupInformation.ApplicationBase)
        Console.WriteLine("Application base of {0}:" & vbCrLf & vbTab & "{1}", _
            domain.FriendlyName, domain.SetupInformation.ApplicationBase)

        AppDomain.Unload(domain)
    End Sub
End Class

' This example produces output similar to the following:
'
'Application base of MyApp.exe:
'        C:\Program Files\MyApp\
'Application base of MyDomain:
'        C:\Program Files\MyApp\MyAppSubfolder\

備註

應用程式基底目錄是元件管理員開始探查元件的位置。The application base directory is where the assembly manager begins probing for assemblies.

ApplicationBase屬性可能會影響授與應用程式域的許可權。The ApplicationBase property can influence which permissions are granted to an application domain. 例如,源自本機電腦的應用程式域通常會根據其來源位置來接收完全信任。For example, an application domain originating from the local computer normally receives full trust based on its location of origin. 不過,如果ApplicationBase將的屬性設定AppDomain為內部網路目錄的完整名稱,則ApplicationBase設定會將授與應用程式域的許可權限制為 LocalIntranet 授與,即使應用程式域也一樣。實際上是源自本機電腦。However, if the ApplicationBase property of that AppDomain is set to the full name of an intranet directory, the ApplicationBase setting restricts the permissions granted to the application domain to a LocalIntranet grant even though the application domain actually originates from the local computer.

安全性

FileIOPermission
以存取路徑資訊。for access to the path information. 相關聯的列舉:PathDiscoveryAssociated enumeration: PathDiscovery

適用於