SecurityAction SecurityAction SecurityAction SecurityAction Enum

Definición

Advertencia

Esta API está ya obsoleta.

Especifica las acciones de seguridad que se pueden realizar mediante la seguridad 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
Herencia
SecurityActionSecurityActionSecurityActionSecurityAction
Atributos

Campos

Assert Assert Assert Assert 3

El código de llamada puede tener acceso al recurso identificado por el objeto de permiso actual, incluso si los autores de la llamada situados en una posición más alta de la pila no tienen permiso para tener acceso al recurso (vea Uso del 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 los autores de llamada de la pila necesitan que se les conceda el permiso especificado por el objeto de permiso actual.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

La posibilidad de tener acceso al recurso especificado por el objeto de permiso actual se deniega a los llamadores, incluso si a estos se les ha concedido acceso al recurso (consulte Utilizar el 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

La clase derivada que hereda la clase o que reemplaza un método debe tener el permiso especificado.The derived class inheriting the class or overriding a method is required to have been granted the specified permission.

LinkDemand LinkDemand LinkDemand LinkDemand 6

Es necesario que el llamador inmediato haya recibido el permiso especificado.The immediate caller is required to have been granted the specified permission. No lo use en .NET Framework 4.NET Framework 4.Do not use in the .NET Framework 4.NET Framework 4. Para la confianza completa, use SecurityCriticalAttribute; para la confianza parcial, use Demand.For full trust, use SecurityCriticalAttribute instead; for partial trust, use Demand.

PermitOnly PermitOnly PermitOnly PermitOnly 5

Solo se puede acceder a los recursos especificados por este objeto de permiso, aunque al código se le haya concedido permiso de acceso a otros 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

Solicitud de los permisos mínimos necesarios para que se ejecute el código.The request for the minimum permissions required for code to run. Esta acción solo se puede usar en el ámbito del ensamblado.This action can only be used within the scope of the assembly.

RequestOptional RequestOptional RequestOptional RequestOptional 9

Solicitud de permisos adicionales que son opcionales (no es necesaria la ejecución).The request for additional permissions that are optional (not required to run). Esta solicitud rechaza implícitamente todos los demás permisos no solicitados específicamente.This request implicitly refuses all other permissions not specifically requested. Esta acción solo se puede usar en el ámbito del ensamblado.This action can only be used within the scope of the assembly.

RequestRefuse RequestRefuse RequestRefuse RequestRefuse 10

Solicitud de que al código de llamada no se le concedan permisos que se puedan usar indebidamente.The request that permissions that might be misused will not be granted to the calling code. Esta acción solo se puede usar en el ámbito del ensamblado.This action can only be used within the scope of the assembly.

Ejemplos

En este ejemplo se muestra cómo notificar a CLR que el código en métodos llamados tiene sólo IsolatedStoragePermissiony también se muestra cómo escribir y leer desde el almacenamiento aislado.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
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 'Main
    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 'App

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

Comentarios

En la tabla siguiente se describe el tiempo que tarda de cada acción de seguridad y los destinos que admite.The following table describes the time that each security action takes place and the targets that it supports.

Importante

En el .NET Framework 4.NET Framework 4, ha quitado la compatibilidad en tiempo de ejecución para exigir las solicitudes de permiso Denegar, RequestMinimum, RequestOptional y RequestRefuse.In the .NET Framework 4.NET Framework 4, runtime support has been removed for enforcing the Deny, RequestMinimum, RequestOptional, and RequestRefuse permission requests. Estas solicitudes no deben usarse en código basado en .NET Framework 4.NET Framework 4 o en una versión posterior.These requests should not be used in code that is based on .NET Framework 4.NET Framework 4 or later. Para obtener más información sobre este y otros cambios, consulte cambios de seguridad.For more information about this and other changes, see Security Changes.

No se debe usar LinkDemand en el .NET Framework 4.NET Framework 4.You should not use LinkDemand in the .NET Framework 4.NET Framework 4. En su lugar, use el SecurityCriticalAttribute para restringir el uso a aplicaciones de plena confianza, o use Demand para restringir los llamadores de confianza parcial.Instead, use the SecurityCriticalAttribute to restrict usage to fully trusted applications, or use Demand to restrict partially trusted callers.

Declaración de acción de seguridadDeclaration of security action Hora de acciónTime of action Destinos admitidosTargets supported
LinkDemand (no use en la .NET Framework 4.NET Framework 4)LinkDemand (do not use in the .NET Framework 4.NET Framework 4) Compilación Just-in-timeJust-in-time compilation Clase, métodoClass, method
InheritanceDemand Tiempo de cargaLoad time Clase, métodoClass, method
Demand Tiempo de ejecuciónRun time Clase, métodoClass, method
Assert Tiempo de ejecuciónRun time Clase, métodoClass, method
Deny (obsoleto en la .NET Framework 4.NET Framework 4)Deny (obsolete in the .NET Framework 4.NET Framework 4) Tiempo de ejecuciónRun time Clase, métodoClass, method
PermitOnly Tiempo de ejecuciónRun time Clase, métodoClass, method
RequestMinimum (obsoleto en la .NET Framework 4.NET Framework 4)RequestMinimum (obsolete in the .NET Framework 4.NET Framework 4) Tiempo de concesiónGrant time EnsambladoAssembly
RequestOptional (obsoleto en la .NET Framework 4.NET Framework 4)RequestOptional (obsolete in the .NET Framework 4.NET Framework 4) Tiempo de concesiónGrant time EnsambladoAssembly
RequestRefuse (obsoleto en la .NET Framework 4.NET Framework 4)RequestRefuse (obsolete in the .NET Framework 4.NET Framework 4) Tiempo de concesiónGrant time EnsambladoAssembly

Para obtener más información acerca de los destinos de atributo, vea Attribute.For additional information about attribute targets, see Attribute.

Se aplica a