AppDomainSetup.ApplicationBase 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取包含应用程序的目录的名称。
public:
property System::String ^ ApplicationBase { System::String ^ get(); };
public:
property System::String ^ ApplicationBase { System::String ^ get(); void set(System::String ^ value); };
public string? ApplicationBase { get; }
public string ApplicationBase { get; set; }
member this.ApplicationBase : string
member this.ApplicationBase : string with get, set
Public ReadOnly Property ApplicationBase As String
Public Property ApplicationBase As String
属性值
应用程序基目录的名称。
实现
示例
以下示例演示如何使用 ApplicationBase 属性设置程序集加载程序开始探测程序集加载到新应用程序域的位置。
备注
必须确保指定的文件夹存在。
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\
*/
open System
let root = AppDomain.CurrentDomain
let setup = AppDomainSetup()
setup.ApplicationBase <-
root.SetupInformation.ApplicationBase + @"MyAppSubfolder\"
let domain = AppDomain.CreateDomain("MyDomain", null, setup)
printfn $"Application base of {root.FriendlyName}:\r\n\t{root.SetupInformation.ApplicationBase}"
printfn $"Application base of {domain.FriendlyName}:\r\n\t{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\
注解
应用程序基目录是程序集管理器开始探测程序集的位置。
该 ApplicationBase 属性可能会影响向应用程序域授予哪些权限。 例如,源自本地计算机的应用程序域通常根据其源位置接收完全信任。 但是,如果 ApplicationBase 此属性 AppDomain 设置为 Intranet 目录的全名,则 ApplicationBase 此设置会将授予给应用程序域的权限限制为 LocalIntranet 授予,即使应用程序域实际上源自本地计算机也是如此。