SecurityException SecurityException SecurityException SecurityException Class

定義

當偵測到安全性錯誤時所擲回的例外狀況。The exception that is thrown when a security error is detected.

public ref class SecurityException : SystemException
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class SecurityException : SystemException
type SecurityException = class
    inherit SystemException
Public Class SecurityException
Inherits SystemException
繼承
屬性

備註

當呼叫端沒有存取資源所需的許可權時,就會擲回例外狀況(exception)。SecurityExceptionA SecurityException exception is thrown when a caller does not have the permissions required to access a resource. 下列範例會具現PermissionSet化物件,其中UIPermission包含允許存取 UI 物件RegistryPermission和剪貼簿的物件,以及防止登錄存取的物件。The following example instantiates a PermissionSet object that includes a UIPermission object to allow access to UI objects and the Clipboard and a RegistryPermission object to prevent registry access. PermissionSet.PermitOnly方法的呼叫表示無論指派給呼叫者的許可權為何,都適用這些許可權。The call to the PermissionSet.PermitOnly method means that these permissions will apply regardless of the permissions assigned to the caller. 因此,嘗試建立登錄機碼SecurityException會擲回。As a result, the attempt to create a registry key throws a SecurityException.

using Microsoft.Win32;
using System;
using System.Security;
using System.Security.Permissions;

public class Example
{
   public static void Main()
   {
      PermissionSet perms = new PermissionSet(null);
      perms.AddPermission(new UIPermission(PermissionState.Unrestricted));
      perms.AddPermission(new RegistryPermission(PermissionState.None));
      perms.PermitOnly();
      
      try {
          RegistryKey key = Registry.CurrentUser.CreateSubKey("MyCompany\\Applications");
          Console.WriteLine("Registry key: {0}", key.Name);
      }
      catch (SecurityException e) {
         Console.WriteLine("Security Exception:\n\n{0}", e.Message);      
      }
   }
}
// The example displays the following output:
//    Security Exception:
//    
//    Request for the permission of type 'System.Security.Permissions.RegistryPermission, 
//    mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
Imports Microsoft.Win32
Imports System.Security
Imports System.Security.Permissions

Module Example
   Public Sub Main()
      Dim perms As New PermissionSet(CType(Nothing, PermissionSet))
      perms.AddPermission(New UIPermission(PermissionState.Unrestricted))
      perms.AddPermission(New RegistryPermission(PermissionState.None))
      perms.PermitOnly()
      
      Try 
          Dim key As RegistryKey = Registry.CurrentUser.CreateSubKey("MyCompany\\Applications")
          Console.WriteLine("Registry key: {0}", key.Name)
      Catch e As SecurityException
         Console.WriteLine("Security Exception:\n\n{0}", e.Message)      
      End Try
   End Sub
End Module
' The example displays the following output:
'    Security Exception:
'    
'    Request for the permission of type 'System.Security.Permissions.RegistryPermission, 
'    mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

SecurityException使用 HRESULT COR_E_SECURITY,其值為0x8013150A。SecurityException uses the HRESULT COR_E_SECURITY, which has the value 0x8013150A.

如需SecurityException類別實例的初始屬性值清單,請參閱特定SecurityException的函式。For a list of the initial property values for an instance of the SecurityException class, see a specific SecurityException constructor.

建構函式

SecurityException() SecurityException() SecurityException() SecurityException()

使用預設屬性,初始化 SecurityException 類別的新執行個體。Initializes a new instance of the SecurityException class with default properties.

SecurityException(SerializationInfo, StreamingContext) SecurityException(SerializationInfo, StreamingContext) SecurityException(SerializationInfo, StreamingContext) SecurityException(SerializationInfo, StreamingContext)

使用序列化資料,初始化 SecurityException 類別的新執行個體。Initializes a new instance of the SecurityException class with serialized data.

SecurityException(String) SecurityException(String) SecurityException(String) SecurityException(String)

使用指定的錯誤訊息,初始化 SecurityException 類別的新執行個體。Initializes a new instance of the SecurityException class with a specified error message.

SecurityException(String, AssemblyName, PermissionSet, PermissionSet, MethodInfo, SecurityAction, Object, IPermission, Evidence) SecurityException(String, AssemblyName, PermissionSet, PermissionSet, MethodInfo, SecurityAction, Object, IPermission, Evidence) SecurityException(String, AssemblyName, PermissionSet, PermissionSet, MethodInfo, SecurityAction, Object, IPermission, Evidence) SecurityException(String, AssemblyName, PermissionSet, PermissionSet, MethodInfo, SecurityAction, Object, IPermission, Evidence)

針對不足的授與集所導致的例外狀況,初始化 SecurityException 類別的新執行個體。Initializes a new instance of the SecurityException class for an exception caused by an insufficient grant set.

SecurityException(String, Exception) SecurityException(String, Exception) SecurityException(String, Exception) SecurityException(String, Exception)

使用指定的錯誤訊息以及造成此例外狀況的內部例外狀況的參考,初始化 SecurityException 類別的新執行個體。Initializes a new instance of the SecurityException class with a specified error message and a reference to the inner exception that is the cause of this exception.

SecurityException(String, Object, Object, MethodInfo, Object, IPermission) SecurityException(String, Object, Object, MethodInfo, Object, IPermission) SecurityException(String, Object, Object, MethodInfo, Object, IPermission) SecurityException(String, Object, Object, MethodInfo, Object, IPermission)

堆疊上 [Deny] 所導致的例外狀況,初始化 SecurityException 類別的新執行個體。Initializes a new instance of the SecurityException class for an exception caused by a Deny on the stack.

SecurityException(String, Type) SecurityException(String, Type) SecurityException(String, Type) SecurityException(String, Type)

使用指定的錯誤訊息和造成此擲回例外狀況的使用權限類型,來初始化 SecurityException 類別的新執行個體。Initializes a new instance of the SecurityException class with a specified error message and the permission type that caused the exception to be thrown.

SecurityException(String, Type, String) SecurityException(String, Type, String) SecurityException(String, Type, String) SecurityException(String, Type, String)

使用指定的錯誤訊息、導致擲回例外狀況的使用權限類型以及使用權限狀態,初始化 SecurityException 類別的新執行個體。Initializes a new instance of the SecurityException class with a specified error message, the permission type that caused the exception to be thrown, and the permission state.

屬性

Action Action Action Action

取得或設定導致例外狀況的安全性動作。Gets or sets the security action that caused the exception.

Data Data Data Data

取得提供例外狀況之其他使用者定義相關資訊的索引鍵/值組集合。Gets a collection of key/value pairs that provide additional user-defined information about the exception.

(Inherited from Exception)
Demanded Demanded Demanded Demanded

取得或設定失敗的要求安全性權限、使用權限集或使用權限集集合。Gets or sets the demanded security permission, permission set, or permission set collection that failed.

DenySetInstance DenySetInstance DenySetInstance DenySetInstance

取得或設定引起要求失敗的拒絕安全性權限、使用權限集或使用權限集集合。Gets or sets the denied security permission, permission set, or permission set collection that caused a demand to fail.

FailedAssemblyInfo FailedAssemblyInfo FailedAssemblyInfo FailedAssemblyInfo

取得或設定失敗組件的相關資訊。Gets or sets information about the failed assembly.

FirstPermissionThatFailed FirstPermissionThatFailed FirstPermissionThatFailed FirstPermissionThatFailed

取得或設定在使用權限集或使用權限集集合中,引起要求失敗的第一個使用權限。Gets or sets the first permission in a permission set or permission set collection that failed the demand.

GrantedSet GrantedSet GrantedSet GrantedSet

取得或設定引起 SecurityException 之組件的授與使用權限集。Gets or sets the granted permission set of the assembly that caused the SecurityException.

HelpLink HelpLink HelpLink HelpLink

取得或設定與這個例外狀況相關聯的說明檔連結。Gets or sets a link to the help file associated with this exception.

(Inherited from Exception)
HResult HResult HResult HResult

取得或設定 HRESULT,它是指派給特定例外狀況的編碼數值。Gets or sets HRESULT, a coded numerical value that is assigned to a specific exception.

(Inherited from Exception)
InnerException InnerException InnerException InnerException

取得造成目前例外狀況的 Exception 執行個體。Gets the Exception instance that caused the current exception.

(Inherited from Exception)
Message Message Message Message

取得描述目前例外狀況的訊息。Gets a message that describes the current exception.

(Inherited from Exception)
Method Method Method Method

取得或設定與例外狀況相關方法的資訊。Gets or sets the information about the method associated with the exception.

PermissionState PermissionState PermissionState PermissionState

取得或設定擲回例外狀況之使用權限的狀態。Gets or sets the state of the permission that threw the exception.

PermissionType PermissionType PermissionType PermissionType

取得或設定失敗的使用權限類型。Gets or sets the type of the permission that failed.

PermitOnlySetInstance PermitOnlySetInstance PermitOnlySetInstance PermitOnlySetInstance

取得或設定引起安全性檢查失敗之只允許堆疊框架其中一部分的使用權限、使用權限集或和使用權限集集合。Gets or sets the permission, permission set, or permission set collection that is part of the permit-only stack frame that caused a security check to fail.

RefusedSet RefusedSet RefusedSet RefusedSet

取得或設定引起 SecurityException 之組件的拒絕使用權限集。Gets or sets the refused permission set of the assembly that caused the SecurityException.

Source Source Source Source

取得或設定造成錯誤的應用程式或物件的名稱。Gets or sets the name of the application or the object that causes the error.

(Inherited from Exception)
StackTrace StackTrace StackTrace StackTrace

取得呼叫堆疊上即時運算框架的字串表示。Gets a string representation of the immediate frames on the call stack.

(Inherited from Exception)
TargetSite TargetSite TargetSite TargetSite

取得擲回目前例外狀況的方法。Gets the method that throws the current exception.

(Inherited from Exception)
Url Url Url Url

取得或設定引起例外狀況之組件的 URL。Gets or sets the URL of the assembly that caused the exception.

Zone Zone Zone Zone

取得或設定引起例外狀況之組件的區域。Gets or sets the zone of the assembly that caused the exception.

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetBaseException() GetBaseException() GetBaseException() GetBaseException()

在衍生類別中覆寫時,傳回一或多個後續的例外狀況的根本原因 ExceptionWhen overridden in a derived class, returns the Exception that is the root cause of one or more subsequent exceptions.

(Inherited from Exception)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext)

使用 SerializationInfo 的資訊設定 SecurityExceptionSets the SerializationInfo with information about the SecurityException.

GetType() GetType() GetType() GetType()

取得目前執行個體的執行階段類型。Gets the runtime type of the current instance.

(Inherited from Exception)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

傳回目前 SecurityException 的表示。Returns a representation of the current SecurityException.

事件

SerializeObjectState SerializeObjectState SerializeObjectState SerializeObjectState

當例外狀況序列化,以建立包含例外狀況相關序列化資料的例外狀況狀態物件時,就會發生此事件。Occurs when an exception is serialized to create an exception state object that contains serialized data about the exception.

(Inherited from Exception)

適用於

另請參閱