SecurityAction SecurityAction SecurityAction SecurityAction Enum

Definição

Aviso

Esta API agora é obsoleta.

Especifica as ações de segurança que podem ser executadas usando a segurança declarativa.Specifies the security actions that can be performed using declarative security.

public enum class SecurityAction
[System.Runtime.InteropServices.ComVisible(true)]
[System.Obsolete("CAS support is not available with Silverlight applications.")]
[System.Serializable]
public enum SecurityAction
type SecurityAction = 
Public Enum SecurityAction
Herança
SecurityActionSecurityActionSecurityActionSecurityAction
Atributos

Campos

Assert Assert Assert Assert 3

O código de chamada pode acessar o recurso identificado pelo objeto de permissão atual, mesmo que os chamadores na pilha não tenham recebido permissão para acessar o recurso (consulte Usando o Método Assert).The calling code can access the resource identified by the current permission object, even if callers higher in the stack have not been granted permission to access the resource (see Using the Assert Method).

Demand Demand Demand Demand 2

Todos os chamadores na pilha de chamadas deverão ter a permissão especificada pelo objeto de permissão atual.All callers higher in the call stack are required to have been granted the permission specified by the current permission object.

Deny Deny Deny Deny 4

A capacidade de acessar o recurso especificado pelo objeto de permissão atual é negado aos chamadores, mesmo que eles tenham recebido permissão para acessá-lo (consulte Usando o Método Deny).The ability to access the resource specified by the current permission object is denied to callers, even if they have been granted permission to access it (see Using the Deny Method).

InheritanceDemand InheritanceDemand InheritanceDemand InheritanceDemand 7

A classe derivada que está herdando a classe ou substituindo um método deverá ter recebido a permissão especificada.The derived class inheriting the class or overriding a method is required to have been granted the specified permission.

LinkDemand LinkDemand LinkDemand LinkDemand 6

O chamador imediato deverá ter recebido a permissão especificada.The immediate caller is required to have been granted the specified permission. Não use no .NET Framework 4.NET Framework 4.Do not use in the .NET Framework 4.NET Framework 4. Para confiança total, use SecurityCriticalAttribute; para confiança parcial, use Demand.For full trust, use SecurityCriticalAttribute instead; for partial trust, use Demand.

PermitOnly PermitOnly PermitOnly PermitOnly 5

Somente os recursos especificados por esse objeto de permissão poderão ser acessados, mesmo que o código tenha recebido permissão para acessar outros recursos.Only the resources specified by this permission object can be accessed, even if the code has been granted permission to access other resources.

RequestMinimum RequestMinimum RequestMinimum RequestMinimum 8

A solicitação para as permissões mínimas necessárias para a execução do código.The request for the minimum permissions required for code to run. Esta ação só pode ser usada no escopo do assembly.This action can only be used within the scope of the assembly.

RequestOptional RequestOptional RequestOptional RequestOptional 9

A solicitação de permissões adicionais que são opcionais (não necessárias para a execução).The request for additional permissions that are optional (not required to run). Essa solicitação recusa implicitamente todas as outras permissões não solicitadas especificamente.This request implicitly refuses all other permissions not specifically requested. Esta ação só pode ser usada no escopo do assembly.This action can only be used within the scope of the assembly.

RequestRefuse RequestRefuse RequestRefuse RequestRefuse 10

A solicitação de permissões que podem ser usadas indevidamente não serão concedidas ao código de chamada.The request that permissions that might be misused will not be granted to the calling code. Esta ação só pode ser usada no escopo do assembly.This action can only be used within the scope of the assembly.

Exemplos

Este exemplo mostra como notificar o CLR que o código nos métodos chamados tem IsolatedStoragePermissionapenas, e também demonstra como gravar e ler de armazenamento isolado.This example shows how to notify the CLR that code in called methods has only IsolatedStoragePermission, and also demonstrates how to write and read from isolated storage.

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.

Comentários

A tabela a seguir descreve a hora em que cada ação de segurança ocorre e os destinos aos quais ela dá suporte.The following table describes the time that each security action takes place and the targets that it supports.

Importante

No, .NET Framework 4.NET Framework 4o suporte ao tempo de execução foi removido para impor as solicitações de permissão Deny, RequestMinimum, RequestOptional e RequestRefuse.In the .NET Framework 4.NET Framework 4, runtime support has been removed for enforcing the Deny, RequestMinimum, RequestOptional, and RequestRefuse permission requests. Essas solicitações não devem ser usadas no código baseado no .NET Framework 4.NET Framework 4 ou posterior.These requests should not be used in code that is based on .NET Framework 4.NET Framework 4 or later. Para obter mais informações sobre essa e outras alterações, consulte Security Changes.For more information about this and other changes, see Security Changes.

Você não deve usar LinkDemand o .NET Framework 4.NET Framework 4no.You should not use LinkDemand in the .NET Framework 4.NET Framework 4. Em vez disso, SecurityCriticalAttribute use o para restringir o uso a aplicativos totalmente confiáveis Demand ou use para restringir chamadores parcialmente confiáveis.Instead, use the SecurityCriticalAttribute to restrict usage to fully trusted applications, or use Demand to restrict partially trusted callers.

Declaração de ação de segurançaDeclaration of security action Hora da açãoTime of action Destinos com suporteTargets supported
LinkDemand(não use no .NET Framework 4.NET Framework 4)LinkDemand (do not use in the .NET Framework 4.NET Framework 4) Compilação just-in-timeJust-in-time compilation Classe, métodoClass, method
InheritanceDemand Tempo de carregamentoLoad time Classe, métodoClass, method
Demand Tempo de execuçãoRun time Classe, métodoClass, method
Assert Tempo de execuçãoRun time Classe, métodoClass, method
Deny(obsoleto no .NET Framework 4.NET Framework 4)Deny (obsolete in the .NET Framework 4.NET Framework 4) Tempo de execuçãoRun time Classe, métodoClass, method
PermitOnly Tempo de execuçãoRun time Classe, métodoClass, method
RequestMinimum(obsoleto no .NET Framework 4.NET Framework 4)RequestMinimum (obsolete in the .NET Framework 4.NET Framework 4) Tempo de concessãoGrant time AssemblyAssembly
RequestOptional(obsoleto no .NET Framework 4.NET Framework 4)RequestOptional (obsolete in the .NET Framework 4.NET Framework 4) Tempo de concessãoGrant time AssemblyAssembly
RequestRefuse(obsoleto no .NET Framework 4.NET Framework 4)RequestRefuse (obsolete in the .NET Framework 4.NET Framework 4) Tempo de concessãoGrant time AssemblyAssembly

Para obter informações adicionais sobre destinos de atributo Attribute, consulte.For additional information about attribute targets, see Attribute.

Aplica-se a