Export (0) Print
Expand All

CodeAccessPermission.RevertAll Method

Causes all previous overrides for the current frame to be removed and no longer in effect.

Namespace: System.Security
Assembly: mscorlib (in mscorlib.dll)

public static void RevertAll ()
public static void RevertAll ()
public static function RevertAll ()
Not applicable.

Exception typeCondition

ExecutionEngineException

There is no previous Assert, Deny, or PermitOnly for the current frame.

If there are no overrides (Assert, Deny, or PermitOnly) for the current frame, an ExecutionEngineException is thrown.

The following code example shows the use of the RevertAll method to revert previous overrides for the current frame.

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 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft