CodeAccessPermission.RevertAll メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > CodeAccessPermission.RevertAll メソッドの意味・解説 

CodeAccessPermission.RevertAll メソッド

現在のフレームに対する以前のオーバーライドをすべて削除し、無効にします。

名前空間: System.Security
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Shared Sub RevertAll
CodeAccessPermission.RevertAll
public static void RevertAll
 ()
public:
static void RevertAll ()
public static void RevertAll
 ()
例外例外
例外の種類条件

ExecutionEngineException

現在のフレームには、Assert、Deny、または PermitOnly が存在しません。

解説解説

現在のフレームに対するオーバーライド (Assert、Deny、または PermitOnly) が存在しない場合、ExecutionEngineException がスローされます。

使用例使用例

RevertAll メソッドを使用して、現在のフレームに対する以前のオーバーライドを元に戻す方法を次のコード例に示します。

Imports System
Imports System.Security
Imports System.Security.Permissions
Imports System.IO



Class UIPermissions

    Public Shared Sub Main()
        Try
            ' Create a new UIPermission that allows access only to OwnClipboard.
            Dim clipboardPermission As 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 e As Exception
            Console.WriteLine("Unexpected exception thrown: "
 + vbLf + e.ToString())
            Console.ReadLine()
        End Try

    End Sub 'Main


    ' Determine whether OwnClipboard can be accessed.
    Private Shared Sub DemandOwnClipboardAccess()
        Try
            ' Create a new UIPermission that allows access to OwnClipboard.
            Dim clipboardPermission As 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 ex As SecurityException
            Console.WriteLine("A security exception was thrown
 while " + _
                "demanding OwnClipboard access permission "
 + vbLf)
            Console.WriteLine(ex.Message)
        Catch ex As Exception
            Console.WriteLine("A fatal exception occurred:"
 + vbLf + ex.ToString())
        End Try

    End Sub 'DemandOwnClipboardAccess


    ' Determine whether OwnClipboard can be accessed.
    Private Shared Sub DemandAllClipboardAccess()
        Try
            ' Create a new UIPermission that allows access to OwnClipboard.
            Dim clipboardPermission As 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 ex As SecurityException
            Console.WriteLine("A security exception was thrown
 while " + _
                "demanding AllClipboard access permission "
 + vbLf)
            Console.WriteLine(ex.Message)
        Catch ex As Exception
            Console.WriteLine("A fatal exception occurred:"
 + vbLf + ex.ToString())
        End Try

    End Sub 'DemandAllClipboardAccess
End Class 'UIPermissions
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());
        }
    }
}
using namespace System;
using namespace System::Security;
using namespace System::Security::Permissions;
using namespace System::IO;

ref class UIPermissions
{
public:
   static void Main()
   {
      try
      {
         // Create a new UIPermission that allows access only to OwnClipboard.
         UIPermission^ clipboardPermission = gcnew UIPermission(
            UIPermissionClipboard::OwnClipboard );
         
         // Deny access to OwnClipboard.
         Console::WriteLine( L"Denying access to OwnClipboard" );
         clipboardPermission->Deny();
         
         // Demand access to files in the specified path.
         DemandOwnClipboardAccess();
         
         // Revert the Deny.
         Console::WriteLine( L"Reverting the Deny." );
         CodeAccessPermission::RevertDeny();
         DemandOwnClipboardAccess();

         // Grant access only to OwnClipboard.
         Console::WriteLine( L"Granting permission only for
 OwnClipboard access." );
         clipboardPermission->PermitOnly();
         DemandAllClipboardAccess();
         
         // Revert the PermitOnly with a call to RevertPermitOnly.
         Console::WriteLine( L"Reverting the PermitOnly." );
         CodeAccessPermission::RevertPermitOnly();
         DemandAllClipboardAccess();

         // Permit access only to OwnClipboard.
         clipboardPermission->PermitOnly();
         DemandAllClipboardAccess();
         
         // Revert the PermitOnly with a call to RevertAll.
         Console::WriteLine( L"Reverting the PermitOnly using
 RevertAll." );
         CodeAccessPermission::RevertAll();
         DemandAllClipboardAccess();

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

private:
   // Determine whether OwnClipboard can be accessed.
   static void DemandOwnClipboardAccess()
   {
      try
      {
         // Create a new UIPermission that allows access to OwnClipboard.
         UIPermission^ clipboardPermission =
            gcnew UIPermission( UIPermissionClipboard::OwnClipboard );
         
         // Verify that callers higher in the stack have been granted
         // the permission.
         Console::WriteLine( L"Demanding OwnClipboard access." );
         clipboardPermission->Demand();
         Console::WriteLine( L"The demand was successful" );
      }
      catch ( SecurityException^ ex ) 
      {
         Console::WriteLine( L"A security exception was thrown while
 "
         L"demanding OwnClipboard access permission \n" );
         Console::WriteLine( ex->Message );
      }
      catch ( Exception^ ex ) 
      {
         Console::WriteLine( L"A fatal exception occurred:\n{0}", ex );
      }
   }

   // Determine whether OwnClipboard can be accessed.
   static void DemandAllClipboardAccess()
   {
      try
      {
         // Create a new UIPermission that allows access to OwnClipboard.
         UIPermission^ clipboardPermission =
            gcnew UIPermission( UIPermissionClipboard::AllClipboard );
         
         // Verify that callers higher in the stack have been granted
         // the permission.
         Console::WriteLine( L"Demanding AllClipboard access." );
         clipboardPermission->Demand();
         Console::WriteLine( L"The demand was successful" );
      }
      catch ( SecurityException^ ex ) 
      {
         Console::WriteLine( L"A security exception was thrown while
 "
         L"demanding AllClipboard access permission \n" );
         Console::WriteLine( ex->Message );
      }
      catch ( Exception^ ex ) 
      {
         Console::WriteLine( L"A fatal exception occurred:\n{0}", ex );
      }
   }

};

int main()
{
   UIPermissions::Main();
}

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
CodeAccessPermission クラス
CodeAccessPermission メンバ
System.Security 名前空間



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「CodeAccessPermission.RevertAll メソッド」の関連用語

CodeAccessPermission.RevertAll メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



CodeAccessPermission.RevertAll メソッドのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS