Share via


SecurityManager.GetStandardSandbox(Evidence) Metoda

Definice

Získá sadu oprávnění, která je bezpečné udělit aplikaci, která má poskytnuté důkazy.

public:
 static System::Security::PermissionSet ^ GetStandardSandbox(System::Security::Policy::Evidence ^ evidence);
public static System.Security.PermissionSet GetStandardSandbox (System.Security.Policy.Evidence evidence);
static member GetStandardSandbox : System.Security.Policy.Evidence -> System.Security.PermissionSet
Public Shared Function GetStandardSandbox (evidence As Evidence) As PermissionSet

Parametry

evidence
Evidence

Důkaz hostitele, který se má shodovat se sadou oprávnění.

Návraty

Sada oprávnění, která se dá použít jako sada udělení pro aplikaci, která má poskytnuté důkazy.

Výjimky

evidence je null.

Příklady

Následující příklad ukazuje, jak použít metodu GetStandardSandbox k získání sady oprávnění pro aplikaci v izolovaném prostoru (sandbox). Další informace o spuštění aplikace v sandboxu najdete v tématu Postupy: Spuštění částečně důvěryhodného kódu v sandboxu.

using System;
using System.Collections;
using System.Diagnostics;
using System.Security;
using System.Security.Permissions;
using System.Security.Policy;
using System.Reflection;
using System.IO;

namespace SimpleSandboxing
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create the permission set to grant to other assemblies.
            // In this case we are granting the permissions found in the LocalIntranet zone.
            Evidence e = new Evidence();
            e.AddHostEvidence(new Zone(SecurityZone.Intranet));
            PermissionSet pset = SecurityManager.GetStandardSandbox(e);

            AppDomainSetup ads = new AppDomainSetup();
            // Identify the folder to use for the sandbox.
            ads.ApplicationBase = "C:\\Sandbox";
            // Copy the application to be executed to the sandbox.
            Directory.CreateDirectory("C:\\Sandbox");
            File.Copy("..\\..\\..\\HelloWorld\\bin\\debug\\HelloWorld.exe", "C:\\sandbox\\HelloWorld.exe", true);

            // Create the sandboxed domain.
            AppDomain sandbox = AppDomain.CreateDomain(
               "Sandboxed Domain",
               e,
               ads,
               pset,
               null);
            sandbox.ExecuteAssemblyByName("HelloWorld");
        }
    }
}
Imports System.Collections
Imports System.Diagnostics
Imports System.Security
Imports System.Security.Permissions
Imports System.Security.Policy
Imports System.Reflection
Imports System.IO



Class Program
    
    Shared Sub Main(ByVal args() As String) 
        ' Create the permission set to grant to other assemblies.
        ' In this case we are granting the permissions found in the LocalIntranet zone.
        Dim e As New Evidence()
        e.AddHostEvidence(New Zone(SecurityZone.Intranet))
        Dim pset As PermissionSet = SecurityManager.GetStandardSandbox(e)
        
        Dim ads As New AppDomainSetup()
        ' Identify the folder to use for the sandbox.
        ads.ApplicationBase = "C:\Sandbox"
        ' Copy the application to be executed to the sandbox.
        Directory.CreateDirectory("C:\Sandbox")
        File.Copy("..\..\..\HelloWorld\bin\debug\HelloWorld.exe", "C:\sandbox\HelloWorld.exe", True)
        
        ' Create the sandboxed domain.
        Dim sandbox As AppDomain = AppDomain.CreateDomain("Sandboxed Domain", e, ads, pset, Nothing)
        sandbox.ExecuteAssemblyByName("HelloWorld")
    
    End Sub
End Class

Poznámky

Poznámka

V rozhraní .NET Framework 4 musí důkazy hostitele v evidence souboru obsahovat System.Security.Policy.Zone důkazy.

Následující tabulka uvádí sady oprávnění, které jsou vráceny pro jednotlivé zóny.

Zóna Sada oprávnění
MyComputer FullTrust
Intranet LocalIntranet
Trusted Internet
Internet Internet
Untrusted Žádné
NoZone Žádné

Lze zvážit další důkazy, například Url nebo Site.

Vrácenou sadu oprávnění může sandbox použít ke spuštění aplikace. Všimněte si, že tato metoda neurčovala zásady, ale pomáhá hostiteli určit, zda je sada oprávnění požadovaná aplikací přiměřená. Tuto metodu lze použít k mapování zóny na sandbox.

Platí pro