Esta documentación está archivada y no tiene mantenimiento.

CodeAccessPermission.RevertAll (Método)

Actualización: noviembre 2007

Hace que se eliminen todos los reemplazos anteriores del marco actual y que dejen de estar en vigor.

Espacio de nombres:  System.Security
Ensamblado:  mscorlib (en mscorlib.dll)

public static void RevertAll()
public static void RevertAll()
public static function RevertAll()

ExcepciónCondición
ExecutionEngineException

No hay un método Assert, Deny o PermitOnly anterior para el marco actual.

Si no hay reemplazos (Assert, Deny o PermitOnly) del marco actual, se produce una excepción de tipo ExecutionEngineException.

En el siguiente ejemplo de código se muestra cómo utilizar el método RevertAll para cualquier reemplazo anterior del marco actual.

using System;
using System.Security;
using System.Security.Permissions;
using System.IO;

class UIPermissions
{
    public static void Main()
    {
        try
        {
            // Create a new UIPermission that allows access only to OwnClipboard.
            UIPermission clipboardPermission = new UIPermission(UIPermissionClipboard.OwnClipboard);
            // Deny access to OwnClipboard.
            Console.WriteLine("Denying access to OwnClipboard");
            clipboardPermission.Deny();
            // Demand access to files in the specified path.
            DemandOwnClipboardAccess();
            // Revert the Deny.
            Console.WriteLine("Reverting the Deny.");
            CodeAccessPermission.RevertDeny();
            DemandOwnClipboardAccess();
            // Grant access only to OwnClipboard.
            Console.WriteLine("Granting permission only for OwnClipboard access.");
            clipboardPermission.PermitOnly();
            DemandAllClipboardAccess();
            // Revert the PermitOnly with a call to RevertPermitOnly.
            Console.WriteLine("Reverting the PermitOnly.");
            CodeAccessPermission.RevertPermitOnly();
            DemandAllClipboardAccess();
            // Permit access only to OwnClipboard.
            clipboardPermission.PermitOnly();
            DemandAllClipboardAccess();
            // Revert the PermitOnly with a call to RevertAll.
            Console.WriteLine("Reverting the PermitOnly using RevertAll.");
            CodeAccessPermission.RevertAll();
            DemandAllClipboardAccess();


            Console.WriteLine("This sample completed successfully; " +
                "press Enter to exit.");
            Console.ReadLine();
        }
        catch (Exception e)
        {
            Console.WriteLine("Unexpected exception thrown: \n" + e.ToString());
            Console.ReadLine();
        }
    }

    // Determine whether OwnClipboard can be accessed.
    private static void DemandOwnClipboardAccess()
    {
        try
        {
            // Create a new UIPermission that allows access to OwnClipboard.
            UIPermission clipboardPermission = new UIPermission(UIPermissionClipboard.OwnClipboard);

            // Verify that callers higher in the stack have been granted
            // the permission.
            Console.WriteLine("Demanding OwnClipboard access.");
            clipboardPermission.Demand();
            Console.WriteLine("The demand was successful");
        }
        catch (SecurityException ex)
        {
            Console.WriteLine("A security exception was thrown while " +
                "demanding OwnClipboard access permission \n");
            Console.WriteLine(ex.Message);
        }
        catch (Exception ex)
        {
            Console.WriteLine("A fatal exception occurred:\n" +
                ex.ToString());
        }
    }

    // Determine whether OwnClipboard can be accessed.
    private static void DemandAllClipboardAccess()
    {
        try
        {
            // Create a new UIPermission that allows access to OwnClipboard.
            UIPermission clipboardPermission = new UIPermission(UIPermissionClipboard.AllClipboard);

            // Verify that callers higher in the stack have been granted
            // the permission.
            Console.WriteLine("Demanding AllClipboard access.");
            clipboardPermission.Demand();
            Console.WriteLine("The demand was successful");
        }
        catch (SecurityException ex)
        {
            Console.WriteLine("A security exception was thrown while " +
                "demanding AllClipboard access permission \n");
            Console.WriteLine(ex.Message);
        }
        catch (Exception ex)
        {
            Console.WriteLine("A fatal exception occurred:\n" +
                ex.ToString());
        }
    }
}


Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

.NET Framework y .NET Compact Framework no admiten todas las versiones de cada plataforma. Para obtener una lista de las versiones compatibles, vea Requisitos de sistema de .NET Framework.

.NET Framework

Compatible con: 3.5, 3.0, 2.0, 1.1, 1.0
Mostrar: