내보내기(0) 인쇄
모두 확장

CodeAccessPermission.RevertAll 메서드

현재 프레임에 대한 이전의 모든 재정의를 제거하고 더 이상 적용되지 않도록 합니다.

네임스페이스: System.Security
어셈블리: mscorlib(mscorlib.dll)

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

예외 형식조건

ExecutionEngineException

현재 프레임에 대한 이전 Assert, Deny 또는 PermitOnly가 없는 경우

현재 프레임에 대해 Assert, Deny 또는 PermitOnly를 재정의하지 않으면 ExecutionEngineException이 throw됩니다.

다음 코드 예제에서는 RevertAll 메서드를 사용하여 현재 프레임에 대한 이전 재정의 작업을 되돌리는 방법을 보여 줍니다.

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 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

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

.NET Framework

2.0, 1.1, 1.0에서 지원

커뮤니티 추가 항목

추가
표시:
© 2014 Microsoft