FileIOPermissionAttribute FileIOPermissionAttribute FileIOPermissionAttribute FileIOPermissionAttribute Class

定義

允許將 FileIOPermission 的安全性動作套用至使用宣告式安全性的程式碼。Allows security actions for FileIOPermission to be applied to code using declarative security. 這個類別無法被繼承。This class cannot be inherited.

public ref class FileIOPermissionAttribute sealed : System::Security::Permissions::CodeAccessSecurityAttribute
[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Struct | System.AttributeTargets.Constructor | System.AttributeTargets.Method, AllowMultiple=true, Inherited=false)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Constructor | System.AttributeTargets.Method | System.AttributeTargets.Struct, AllowMultiple=true, Inherited=false)]
[System.Serializable]
public sealed class FileIOPermissionAttribute : System.Security.Permissions.CodeAccessSecurityAttribute
type FileIOPermissionAttribute = class
    inherit CodeAccessSecurityAttribute
Public NotInheritable Class FileIOPermissionAttribute
Inherits CodeAccessSecurityAttribute
繼承
屬性

範例

下列程式碼範例示範如何要求FileIOPermission使用FileIOPermissionAttribute類別,表示要授與程式碼的唯一權限。The following code example demonstrates how to request FileIOPermission by using the FileIOPermissionAttribute class, indicating the only permission that is to be granted to the code.

[FileIOPermissionAttribute(SecurityAction::PermitOnly,ViewAndModify="C:\\example\\sample.txt")]
[FileIOPermissionAttribute(SecurityAction.PermitOnly, ViewAndModify = "C:\\example\\sample.txt")]
<FileIOPermissionAttribute(SecurityAction.PermitOnly, _
ViewAndModify:="C:\example\sample.txt")> Public Class SampleClass

下列範例示範如何要求呼叫的程式碼能夠毫無限制地FileIOPermissionThe following example shows how to demand that the calling code has unrestricted FileIOPermission. 您通常會在 managed 程式庫 (Dll),以協助防止可能有害的程式碼中的方法或類別提出要求。You typically make demands in managed libraries (DLLs) to help protect methods or classes from potentially harmful code.

[FileIOPermissionAttribute(SecurityAction::Demand,Unrestricted=true)]
[FileIOPermissionAttribute(SecurityAction.Demand, Unrestricted=true)]
<FileIOPermissionAttribute(SecurityAction.Demand, _
 Unrestricted := True)> Public Class SampleClass

備註

使用絕對路徑會指定檔案和目錄。Files and directories are specified using absolute paths. 時存取檔案,建立或開啟檔案時,就是會執行安全性檢查。When accessing files, a security check is performed when the file is created or opened. 安全性檢查不完成一次,除非關閉並重新開啟該檔案。The security check is not done again unless the file is closed and reopened. 正在檢查權限,當第一次存取檔案,因為開啟檔案時發生一次,讀取和寫入可能會發生多次,最小化安全性檢查,對應用程式效能的影響。Checking permissions when the file is first accessed minimizes the impact of the security check on application performance because opening a file happens only once, while reading and writing can happen multiple times.

允許宣告的範圍取決於SecurityAction用。The scope of the declaration that is allowed depends on the SecurityAction that is used.

安全性屬性所宣告的安全性資訊會儲存屬性目標的中繼資料,並在執行階段存取系統。The security information declared by a security attribute is stored in the metadata of the attribute target and is accessed by the system at run time. 安全性屬性僅用於宣告式安全性。Security attributes are used only for declarative security. 命令式安全性,使用對應的權限類別。For imperative security, use the corresponding permission class.

警告

Unrestricted FileIOPermission 授與檔案系統,包括多個可用來存取單一指定檔案的路徑名稱內的所有路徑的權限。Unrestricted FileIOPermission grants permission for all paths within a file system, including multiple pathnames that can be used to access a single given file. 若要Deny存取至檔案,您必須Deny所有可能的檔案路徑。To Deny access to a file, you must Deny all possible paths to the file. 比方說,如果\\server\share 會為對應到網路磁碟機 XDeny存取權\\server\share\file,您必須Deny \\server\share\file X:\file,您可以使用任何其他路徑來存取檔案。For example, if \\server\share is mapped to the network drive X, to Deny access to \\server\share\file, you must Deny \\server\share\file, X:\file and any other path that you can use to access the file.

建構函式

FileIOPermissionAttribute(SecurityAction) FileIOPermissionAttribute(SecurityAction) FileIOPermissionAttribute(SecurityAction) FileIOPermissionAttribute(SecurityAction)

使用指定的 FileIOPermissionAttribute 初始化 SecurityAction 類別的新執行個體。Initializes a new instance of the FileIOPermissionAttribute class with the specified SecurityAction.

屬性

Action Action Action Action

取得或設定安全性動作。Gets or sets a security action.

(Inherited from SecurityAttribute)
All All All All

取得或設定字串值所指定檔案或目錄的完整存取權。Gets or sets full access for the file or directory that is specified by the string value.

AllFiles AllFiles AllFiles AllFiles

取得或設定所有檔案的存取權。Gets or sets the permitted access to all files.

AllLocalFiles AllLocalFiles AllLocalFiles AllLocalFiles

取得或設定允許的所有本機檔案存取。Gets or sets the permitted access to all local files.

Append Append Append Append

取得或設定字串值所指定檔案或目錄的附加存取權。Gets or sets append access for the file or directory that is specified by the string value.

ChangeAccessControl ChangeAccessControl ChangeAccessControl ChangeAccessControl

取得或設定可以在其中變更存取控制資訊的檔案或目錄。Gets or sets the file or directory in which access control information can be changed.

PathDiscovery PathDiscovery PathDiscovery PathDiscovery

取得或設定要授與路徑探索 (Discovery) 的檔案或目錄。Gets or sets the file or directory to which to grant path discovery.

Read Read Read Read

取得或設定字串值所指定檔案或目錄的讀取權限。Gets or sets read access for the file or directory specified by the string value.

TypeId TypeId TypeId TypeId

在衍生類別中實作時,取得這個 Attribute 的唯一識別碼。When implemented in a derived class, gets a unique identifier for this Attribute.

(Inherited from Attribute)
Unrestricted Unrestricted Unrestricted Unrestricted

取得或設定數值,表示是否宣告由屬性所保護之資源的完整 (不受限制的) 使用權限。Gets or sets a value indicating whether full (unrestricted) permission to the resource protected by the attribute is declared.

(Inherited from SecurityAttribute)
ViewAccessControl ViewAccessControl ViewAccessControl ViewAccessControl

取得或設定可以在其中檢視存取控制資訊的檔案或目錄。Gets or sets the file or directory in which access control information can be viewed.

ViewAndModify ViewAndModify ViewAndModify ViewAndModify

取得或設定可以在其中檢視和修改檔案資料的檔案或目錄。Gets or sets the file or directory in which file data can be viewed and modified.

Write Write Write Write

取得或設定字串值所指定檔案或目錄的寫入權限。Gets or sets write access for the file or directory specified by the string value.

方法

CreatePermission() CreatePermission() CreatePermission() CreatePermission()

建立及傳回新的 FileIOPermissionCreates and returns a new FileIOPermission.

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

傳回值,這個值指出此執行個體是否與指定的物件相等。Returns a value that indicates whether this instance is equal to a specified object.

(Inherited from Attribute)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

傳回這個執行個體的雜湊碼。Returns the hash code for this instance.

(Inherited from Attribute)
GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
IsDefaultAttribute() IsDefaultAttribute() IsDefaultAttribute() IsDefaultAttribute()

在衍生類別中覆寫時,表示這個執行個體的值是衍生類別的預設值。When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.

(Inherited from Attribute)
Match(Object) Match(Object) Match(Object) Match(Object)

在衍生類別中覆寫時,會傳回值,表示這個執行個體是否等於指定物件。When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(Inherited from Attribute)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

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

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

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)

明確介面實作

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。Maps a set of names to a corresponding set of dispatch identifiers.

(Inherited from Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

擷取物件的類型資訊,可以用來取得介面的類型資訊。Retrieves the type information for an object, which can be used to get the type information for an interface.

(Inherited from Attribute)
_Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32)

擷取物件提供的類型資訊介面數目 (0 或 1)。Retrieves the number of type information interfaces that an object provides (either 0 or 1).

(Inherited from Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供物件所公開的屬性和方法的存取權。Provides access to properties and methods exposed by an object.

(Inherited from Attribute)

適用於

另請參閱