SecurityAction 열거형

정의

주의

Code Access Security is not supported or honored by the runtime.

주의

CAS support is not available with Silverlight applications.

선언적 보안을 사용하여 수행할 수 있는 보안 작업을 지정합니다.

public enum class SecurityAction
[System.Obsolete("Code Access Security is not supported or honored by the runtime.", DiagnosticId="SYSLIB0003", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public enum SecurityAction
public enum SecurityAction
[System.Serializable]
public enum SecurityAction
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public enum SecurityAction
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Obsolete("CAS support is not available with Silverlight applications.")]
public enum SecurityAction
[<System.Obsolete("Code Access Security is not supported or honored by the runtime.", DiagnosticId="SYSLIB0003", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
type SecurityAction = 
type SecurityAction = 
[<System.Serializable>]
type SecurityAction = 
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type SecurityAction = 
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Obsolete("CAS support is not available with Silverlight applications.")>]
type SecurityAction = 
Public Enum SecurityAction
상속
SecurityAction
특성

필드

Assert 3

스택의 상위 호출자에게 리소스에 액세스할 수 있는 권한이 부여되지 않더라도 호출 코드에서 현재 사용 권한 개체로 식별되는 리소스에 액세스할 수 있습니다(Assert 메서드 사용 참조).

Demand 2

호출 스택의 상위에 있는 모든 호출자에게 현재 사용 권한 개체가 지정한 사용 권한이 부여되었어야 합니다.

Deny 4

스택의 상위 호출자에게 리소스에 액세스할 수 있는 권한이 부여되더라도 현재 사용 권한 개체로 식별되는 리소스에 액세스할 수 있습니다(Deny 메서드 사용 참조).

InheritanceDemand 7

클래스를 상속하거나 메서드를 재정의하는 파생 클래스에는 지정된 사용 권한을 부여해야 합니다.

LinkDemand 6

직접 실행 호출자에게 지정된 사용 권한이 부여되었어야 합니다. .NET Framework 4에서는 사용하지 마세요. 완전 신뢰의 경우 SecurityCriticalAttribute를 사용하고, 부분 신뢰의 경우 Demand를 사용합니다.

PermitOnly 5

코드에 다른 리소스에 액세스할 수 있는 권한이 부여되더라도 이 권한 개체가 지정한 리소스에만 액세스할 수 있습니다.

RequestMinimum 8

코드를 실행하는 데 필요한 최소 사용 권한에 대한 요청입니다. 이 작업은 어셈블리 범위 내에서만 사용할 수 있습니다.

RequestOptional 9

선택적인 추가 사용 권한에 대한 요청입니다(실행하는 데 필수는 아님). 이 요청은 특별히 요청되지 않은 다른 모든 사용 권한을 암시적으로 거부합니다. 이 작업은 어셈블리 범위 내에서만 사용할 수 있습니다.

RequestRefuse 10

잘못 사용될 수 있는 사용 권한을 호출 코드에 부여하지 않도록 하는 요청입니다. 이 작업은 어셈블리 범위 내에서만 사용할 수 있습니다.

예제

이 예제에서는 호출된 메서드의 코드가 IsolatedStoragePermission만 포함한다는 것을 CLR에 알리는 방법과 격리된 스토리지에서 쓰고 읽는 방법을 보여줍니다.

using namespace System;
using namespace System::Security;
using namespace System::Security::Permissions;
using namespace System::IO::IsolatedStorage;
using namespace System::IO;


static void WriteIsolatedStorage()
{
    try
    {
        // Attempt to create a storage file that is isolated by
        // user and assembly. IsolatedStorageFilePermission
        // granted to the attribute at the top of this file
        // allows CLR to load this assembly and execution of this
        // statement.
        Stream^ fileCreateStream = gcnew
            IsolatedStorageFileStream(
            "AssemblyData",
            FileMode::Create,
            IsolatedStorageFile::GetUserStoreForAssembly());

        StreamWriter^ streamWriter = gcnew StreamWriter(
            fileCreateStream);
        try
        {
            // Write some data out to the isolated file.

            streamWriter->Write("This is some test data.");
            streamWriter->Close();	
        }
        finally
        {
            delete fileCreateStream;
            delete streamWriter;
        } 
    }
    catch (IOException^ ex)
    {
        Console::WriteLine(ex->Message);
    }

    try
    {
        Stream^ fileOpenStream =
            gcnew IsolatedStorageFileStream(
            "AssemblyData",
            FileMode::Open,
            IsolatedStorageFile::GetUserStoreForAssembly());
        // Attempt to open the file that was previously created.

        StreamReader^ streamReader = gcnew StreamReader(
            fileOpenStream);
        try
        { 
            // Read the data from the file and display it.

            Console::WriteLine(streamReader->ReadLine());
            streamReader->Close();
        }
        finally
        {
            delete fileOpenStream;
            delete streamReader;
        }
    }
    catch (FileNotFoundException^ ex)
    {
        Console::WriteLine(ex->Message);
    }
    catch (IOException^ ex)
    {
        Console::WriteLine(ex->Message);
    }
}
// Notify the CLR to only grant IsolatedStorageFilePermission to called methods. 
// This restricts the called methods to working only with storage files that are isolated 
// by user and assembly.
[IsolatedStorageFilePermission(SecurityAction::PermitOnly, UsageAllowed = IsolatedStorageContainment::AssemblyIsolationByUser)]
int main()
{
    WriteIsolatedStorage();
}

// This code produces the following output.
//
//  This is some test data.
using System;
using System.Security.Permissions;
using System.IO.IsolatedStorage;
using System.IO;

// Notify the CLR to only grant IsolatedStorageFilePermission to called methods.
// This restricts the called methods to working only with storage files that are isolated
// by user and assembly.
[IsolatedStorageFilePermission(SecurityAction.PermitOnly, UsageAllowed = IsolatedStorageContainment.AssemblyIsolationByUser)]
public sealed class App
{
    static void Main()
    {
        WriteIsolatedStorage();
    }
    private static void WriteIsolatedStorage()
    {
        // Attempt to create a storage file that is isolated by user and assembly.
        // IsolatedStorageFilePermission granted to the attribute at the top of this file
        // allows CLR to load this assembly and execution of this statement.
        using (Stream s = new IsolatedStorageFileStream("AssemblyData", FileMode.Create, IsolatedStorageFile.GetUserStoreForAssembly()))
        {

            // Write some data out to the isolated file.
            using (StreamWriter sw = new StreamWriter(s))
            {
                sw.Write("This is some test data.");
            }
        }

        // Attempt to open the file that was previously created.
        using (Stream s = new IsolatedStorageFileStream("AssemblyData", FileMode.Open, IsolatedStorageFile.GetUserStoreForAssembly()))
        {
            // Read the data from the file and display it.
            using (StreamReader sr = new StreamReader(s))
            {
                Console.WriteLine(sr.ReadLine());
            }
        }
    }
}

// This code produces the following output.
//
//  Some test data.
Option Strict On
Imports System.Security.Permissions
Imports System.IO.IsolatedStorage
Imports System.IO


' Notify the CLR to only grant IsolatedStorageFilePermission to called methods. 
' This restricts the called methods to working only with storage files that are isolated 
' by user and assembly.
<IsolatedStorageFilePermission(SecurityAction.PermitOnly, UsageAllowed:=IsolatedStorageContainment.AssemblyIsolationByUser)> _
Public NotInheritable Class App

    Shared Sub Main()
        WriteIsolatedStorage()
    End Sub
    Shared Sub WriteIsolatedStorage()
        ' Attempt to create a storage file that is isolated by user and assembly.
        ' IsolatedStorageFilePermission granted to the attribute at the top of this file 
        ' allows CLR to load this assembly and execution of this statement.
        Dim s As New IsolatedStorageFileStream("AssemblyData", FileMode.Create, IsolatedStorageFile.GetUserStoreForAssembly())
        Try

            ' Write some data out to the isolated file.
            Dim sw As New StreamWriter(s)
            Try
                sw.Write("This is some test data.")
            Finally
                sw.Dispose()
            End Try
        Finally
            s.Dispose()
        End Try

        ' Attempt to open the file that was previously created.
        Dim t As New IsolatedStorageFileStream("AssemblyData", FileMode.Open, IsolatedStorageFile.GetUserStoreForAssembly())
        Try
            ' Read the data from the file and display it.
            Dim sr As New StreamReader(t)
            Try
                Console.WriteLine(sr.ReadLine())
            Finally
                sr.Dispose()
            End Try
        Finally
            t.Dispose()
        End Try

    End Sub
End Class

' This code produces the following output.
'
'  Some test data.

설명

주의

CAS(코드 액세스 보안)는 모든 버전의 .NET Framework 및 .NET에서 더 이상 사용되지 않습니다. 최신 버전의 .NET은 CAS 주석을 적용하지 않으며 CAS 관련 API를 사용하는 경우 오류를 생성합니다. 개발자는 보안 작업을 수행하는 대체 방법을 찾아야 합니다.

다음 표에서는 각 보안 작업이 수행되는 시간과 지원하는 대상에 대해 설명합니다.

중요

.NET Framework 4에서는 거부, RequestMinimum, RequestOptional 및 RequestRefuse 권한 요청을 적용하기 위한 런타임 지원이 제거되었습니다. 이러한 요청은 .NET Framework 4 이상을 기반으로 하는 코드에서 사용하면 안 됩니다. 이 변경 내용 및 기타 변경 내용에 대한 자세한 내용은 보안 변경 내용을 참조하세요.

.NET Framework 4에서는 사용하지 LinkDemand 않아야 합니다. 대신 합니다 SecurityCriticalAttribute 완전히 신뢰할 수 있는 애플리케이션 사용을 제한 하거나 사용 하 여 Demand 부분적으로 신뢰할 수 있는 호출자를 제한 하 합니다.

보안 동작 선언 작업 시간 지원되는 대상
LinkDemand(.NET Framework 4에서는 사용하지 마세요. Just-In-Time 컴파일 클래스, 메서드
InheritanceDemand 로드 시간 클래스, 메서드
Demand 실행 시간 클래스, 메서드
Assert 실행 시간 클래스, 메서드
Deny(.NET Framework 4에서는 사용되지 않음) 실행 시간 클래스, 메서드
PermitOnly 실행 시간 클래스, 메서드
RequestMinimum(.NET Framework 4에서는 사용되지 않음) 허용 시간 어셈블리
RequestOptional(.NET Framework 4에서는 사용되지 않음) 허용 시간 어셈블리
RequestRefuse(.NET Framework 4에서는 사용되지 않음) 허용 시간 어셈블리

특성 대상에 대한 자세한 내용은 다음을 참조하세요 Attribute.

적용 대상