AppDomain.IsFullyTrusted 속성

정의

현재 애플리케이션 도메인에 로드된 어셈블리가 완전 신뢰로 실행되는지를 나타내는 값을 가져옵니다.Gets a value that indicates whether assemblies that are loaded into the current application domain execute with full trust.

public:
 property bool IsFullyTrusted { bool get(); };
public bool IsFullyTrusted { get; }
member this.IsFullyTrusted : bool
Public ReadOnly Property IsFullyTrusted As Boolean

속성 값

현재 애플리케이션 도메인에 로드된 어셈블리가 완전 신뢰로 실행되면 true이고, 그렇지 않으면 false입니다.true if assemblies that are loaded into the current application domain execute with full trust; otherwise, false.

예제

다음 예제는 IsFullyTrusted 속성 및 Assembly.IsFullyTrusted 완전히 신뢰할 수 있는 고 부분적으로 신뢰할 수 있는 애플리케이션 도메인을 사용 하 여 속성입니다.The following example demonstrates the IsFullyTrusted property and the Assembly.IsFullyTrusted property with fully trusted and partially trusted application domains. 완전히 신뢰할 수 있는 애플리케이션 도메인은 애플리케이션에 대 한 기본 애플리케이션 도메인입니다.The fully trusted application domain is the default application domain for the application. 부분적으로 신뢰할 수 있는 애플리케이션 도메인을 사용 하 여 만들어집니다는 AppDomain.CreateDomain(String, Evidence, AppDomainSetup, PermissionSet, StrongName[]) 메서드 오버 로드 합니다.The partially trusted application domain is created by using the AppDomain.CreateDomain(String, Evidence, AppDomainSetup, PermissionSet, StrongName[]) method overload.

이 예제에서는 사용을 Worker 에서 파생 된 클래스 MarshalByRefObject이므로 애플리케이션 도메인 경계를 넘어 마샬링될 수 있습니다.The example uses a Worker class that derives from MarshalByRefObject, so it can be marshaled across application domain boundaries. 이 예에서는 만듭니다는 Worker 기본 애플리케이션 도메인에 있는 개체입니다.The example creates a Worker object in the default application domain. 그런 다음 호출 하는 TestIsFullyTrusted 애플리케이션 도메인 및 애플리케이션 도메인에 로드 되는 두 어셈블리에 대 한 속성 값을 표시 하는 방법:.NET Framework 및 예제에서는 어셈블리의 일부인 인 mscorlib을 합니다.It then calls the TestIsFullyTrusted method to display the property value for the application domain and for two assemblies that are loaded into the application domain: mscorlib, which is part of the .NET Framework, and the example assembly. 애플리케이션 도메인이 완전히 신뢰할 수 있는 이므로 두 어셈블리는 완전히 신뢰 합니다.The application domain is fully trusted, so both assemblies are fully trusted.

이 예에서는 다른 만듭니다 Worker 샌드박스 애플리케이션 도메인에 다시 호출 하는 개체는 TestIsFullyTrusted 메서드.The example creates another Worker object in a sandboxed application domain and again calls the TestIsFullyTrusted method. 부분적으로 신뢰할 수 있는 애플리케이션 도메인 에서도 Mscorlib는 신뢰할 수 있으며 항상 이지만 예제 어셈블리가 부분적으로 신뢰할 수 있습니다.Mscorlib is always trusted, even in a partially trusted application domain, but the example assembly is partially trusted.

using System;
 
namespace SimpleSandboxing
{
    public class Worker : MarshalByRefObject
    {
        static void Main()
        {
            Worker w = new Worker();
            w.TestIsFullyTrusted();

            AppDomain adSandbox = GetInternetSandbox();
            w = (Worker) adSandbox.CreateInstanceAndUnwrap(
                               typeof(Worker).Assembly.FullName,
                               typeof(Worker).FullName);
            w.TestIsFullyTrusted();
        }

        public void TestIsFullyTrusted()
        {
            AppDomain ad = AppDomain.CurrentDomain;
            Console.WriteLine("\r\nApplication domain '{0}': IsFullyTrusted = {1}",
                                        ad.FriendlyName, ad.IsFullyTrusted);

            Console.WriteLine("   IsFullyTrusted = {0} for the current assembly",
                             typeof(Worker).Assembly.IsFullyTrusted);

            Console.WriteLine("   IsFullyTrusted = {0} for mscorlib",
                                        typeof(int).Assembly.IsFullyTrusted);
        }

        // ------------ Helper method ---------------------------------------
        static AppDomain GetInternetSandbox()
        {
            // Create the permission set to grant to all assemblies.
            System.Security.Policy.Evidence hostEvidence = new System.Security.Policy.Evidence();
            hostEvidence.AddHostEvidence(new System.Security.Policy.Zone(
                                                         System.Security.SecurityZone.Internet));
            System.Security.PermissionSet pset = 
                                System.Security.SecurityManager.GetStandardSandbox(hostEvidence);

            // Identify the folder to use for the sandbox.
            AppDomainSetup ads = new AppDomainSetup();
            ads.ApplicationBase = System.IO.Directory.GetCurrentDirectory();
 
            // Create the sandboxed application domain.
            return AppDomain.CreateDomain("Sandbox", hostEvidence, ads, pset, null); 
        }
    }
}

/* This example produces output similar to the following:

Application domain 'Example.exe': IsFullyTrusted = True
   IsFullyTrusted = True for the current assembly
   IsFullyTrusted = True for mscorlib

Application domain 'Sandbox': IsFullyTrusted = False
   IsFullyTrusted = False for the current assembly
   IsFullyTrusted = True for mscorlib
 */
Public Class Worker
    Inherits MarshalByRefObject
    
    Shared Sub Main()
 
        Dim w As New Worker()
        w.TestIsFullyTrusted()
        
        Dim adSandbox As AppDomain = GetInternetSandbox()
        w = CType(adSandbox.CreateInstanceAndUnwrap(
                            GetType(Worker).Assembly.FullName, 
                            GetType(Worker).FullName), 
                  Worker)
        w.TestIsFullyTrusted()
    
    End Sub 
    
    Public Sub TestIsFullyTrusted() 

        Dim ad As AppDomain = AppDomain.CurrentDomain
        Console.WriteLine(vbCrLf & "Application domain '{0}': IsFullyTrusted = {1}", 
                          ad.FriendlyName, ad.IsFullyTrusted)
        
        Console.WriteLine("   IsFullyTrusted = {0} for the current assembly", 
                          GetType(Worker).Assembly.IsFullyTrusted)
        
        Console.WriteLine("   IsFullyTrusted = {0} for mscorlib", 
                          GetType(Integer).Assembly.IsFullyTrusted)
    
    End Sub 
    
    ' ------------ Helper method ---------------------------------------
    Shared Function GetInternetSandbox() As AppDomain 

        ' Create the permission set to grant to all assemblies.
        Dim hostEvidence As New System.Security.Policy.Evidence()
        hostEvidence.AddHostEvidence(
                    New System.Security.Policy.Zone(System.Security.SecurityZone.Internet))
        Dim pset As System.Security.PermissionSet = 
                           System.Security.SecurityManager.GetStandardSandbox(hostEvidence)
        
        ' Identify the folder to use for the sandbox.
        Dim ads As New AppDomainSetup()
        ads.ApplicationBase = System.IO.Directory.GetCurrentDirectory()
        
        ' Create the sandboxed application domain.
        Return AppDomain.CreateDomain("Sandbox", hostEvidence, ads, pset, Nothing)
    
    End Function 
End Class 

' This example produces output similar to the following:
'
'Application domain 'Example.exe': IsFullyTrusted = True
'   IsFullyTrusted = True for the current assembly
'   IsFullyTrusted = True for mscorlib
'
'Application domain 'Sandbox': IsFullyTrusted = False
'   IsFullyTrusted = False for the current assembly
'   IsFullyTrusted = True for mscorlib
' 

설명

이 메서드는 항상 반환 true 데스크톱에서 실행 되는 애플리케이션의 기본 애플리케이션 도메인에 대 한 합니다.This method always returns true for the default application domain of an application that runs on the desktop. 반환 false 를 사용 하 여 생성 된 샌드박스 애플리케이션 도메인을 AppDomain.CreateDomain(String, Evidence, AppDomainSetup, PermissionSet, StrongName[]) 애플리케이션 도메인에 부여 된 권한은 완전 신뢰와 동일 하지 않으면 메서드를 오버 로드 합니다.It returns false for a sandboxed application domain that was created by using the AppDomain.CreateDomain(String, Evidence, AppDomainSetup, PermissionSet, StrongName[]) method overload, unless the permissions that are granted to the application domain are equivalent to full trust.

적용 대상