SecurityManager.GetStandardSandbox(Evidence) メソッド

定義

指定された証拠を持つアプリケーションに安全に付与できるアクセス許可セットを取得します。

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

パラメーター

evidence
Evidence

アクセス許可セットと一致させるホスト証拠。

戻り値

PermissionSet

指定された証拠を持つアプリケーションの許可セットとして使用できるアクセス許可セット。

例外

evidencenullです。

次の例は、このメソッドを使用 GetStandardSandbox して、サンドボックス アプリケーションのアクセス許可セットを取得する方法を示しています。 サンドボックスでアプリケーションを実行する方法の詳細については、「 方法: サンドボックスで部分的に信頼されたコードを実行する」を参照してください

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

注釈

注意

.NET Framework 4では、宿主証拠にevidence証拠が含まれているSystem.Security.Policy.Zone必要がある。

次の表は、各ゾーンに対して返されるアクセス許可セットを示しています。

ゾーン アクセス許可セット
MyComputer FullTrust
Intranet LocalIntranet
Trusted Internet
Internet Internet
Untrusted なし
NoZone なし

その他の証拠は、例えば Url 、または Site、考慮され得る。

返されたアクセス許可セットは、サンドボックスでアプリケーションを実行するために使用できます。 このメソッドはポリシーを指定しませんが、アプリケーションによって要求されたアクセス許可セットが妥当かどうかをホストが判断するのに役立ちます。 このメソッドを使用して、ゾーンをサンドボックスにマップできます。

適用対象