CodeAccessPermission.RevertAll-Methode
Veranlasst, dass alle vorhergehenden Überschreibungen für den aktuellen Rahmen entfernt werden und nicht mehr wirksam sind.
Namespace: System.Security
Assembly: mscorlib (in mscorlib.dll)
Syntax
'Declaration
Public Shared Sub RevertAll
'Usage
CodeAccessPermission.RevertAll
public static void RevertAll ()
public:
static void RevertAll ()
public static void RevertAll ()
public static function RevertAll ()
Ausnahmen
Ausnahmetyp | Bedingung |
---|---|
Es ist kein vorhergehendes Assert, Deny oder PermitOnly für den aktuellen Rahmen vorhanden. |
Hinweise
Wenn für den aktuellen Rahmen keine Überschreibungen vorgenommen wurden (Assert, Deny oder PermitOnly), wird eine ExecutionEngineException ausgelöst.
Beispiel
Im folgenden Codebeispiel wird die Verwendung der RevertAll-Methode zum Wiederherstellen vorheriger Überschreibungen für den aktuellen Rahmen veranschaulicht.
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();
}
Plattformen
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 unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
Siehe auch
Referenz
CodeAccessPermission-Klasse
CodeAccessPermission-Member
System.Security-Namespace