FileIOPermissionAttribute 类


允许对要使用声明性安全应用到代码中的 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.Constructor | System.AttributeTargets.Method | System.AttributeTargets.Struct, AllowMultiple=true, Inherited=false)]
public sealed class FileIOPermissionAttribute : System.Security.Permissions.CodeAccessSecurityAttribute
type FileIOPermissionAttribute = class
    inherit CodeAccessSecurityAttribute
Public NotInheritable Class FileIOPermissionAttribute
Inherits CodeAccessSecurityAttribute


下面的代码示例演示如何使用 @no__t 1 类请求 @no__t 0,指示要授予代码的唯一权限。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")> Public Class SampleClass

下面的示例演示如何要求调用代码具有不受限制的 @no__t 0。The following example shows how to demand that the calling code has unrestricted FileIOPermission. 通常会在托管库(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)> Public Class SampleClass



不再支持部分受信任的代码。Partially trusted code is no longer supported. 此属性在 .NET Core 中不起作用。This attribute has no effect in .NET Core.

使用绝对路径指定文件和目录。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.

允许的声明的范围取决于所使用的 SecurityActionThe 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. 若要对文件 @no__t 0 访问,必须将所有可能的路径 @no__t 到该文件。To Deny access to a file, you must Deny all possible paths to the file. 例如,如果将 \ \ server\share 映射到网络驱动器 X,以 Deny 访问 \ \ 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 类的新实例。Initializes a new instance of the FileIOPermissionAttribute class with the specified SecurityAction.



获取或设置安全性操作。Gets or sets a security action.

(继承自 SecurityAttribute)

获取或设置对字符串值所指定的文件或目录的完全访问权限。Gets or sets full access for the file or directory that is specified by the string value.


获取或设置对所有文件的允许访问权限。Gets or sets the permitted access to all files.


获取或设置对所有本地文件的允许访问权限。Gets or sets the permitted access to all local files.


获取或设置对字符串值所指定的文件或目录的追加访问权限。Gets or sets append access for the file or directory that is specified by the string value.


获取或设置可在其中更改访问控制信息的文件或目录。Gets or sets the file or directory in which access control information can be changed.


获取或设置针对其授予路径发现权限的文件或目录。Gets or sets the file or directory to which to grant path discovery.


获取或设置对字符串值所指定的文件或目录的读访问权限。Gets or sets read access for the file or directory specified by the string value.


在派生类中实现时,获取此 Attribute 的唯一标识符。When implemented in a derived class, gets a unique identifier for this Attribute.

(继承自 Attribute)

获取或设置一个值,该值指示是否声明了对受该特性保护的资源有完全(无限制的)权限。Gets or sets a value indicating whether full (unrestricted) permission to the resource protected by the attribute is declared.

(继承自 SecurityAttribute)

获取或设置可在其中查看访问控制信息的文件或目录。Gets or sets the file or directory in which access control information can be viewed.


获取或设置可在其中查看并修改文件数据的文件或目录。Gets or sets the file or directory in which file data can be viewed and modified.


获取或设置对字符串值所指定的文件或目录的写访问权限。Gets or sets write access for the file or directory specified by the string value.



创建并返回一个新的 FileIOPermissionCreates and returns a new FileIOPermission.


返回一个值,该值指示此实例是否与指定的对象相等。Returns a value that indicates whether this instance is equal to a specified object.

(继承自 Attribute)

返回此实例的哈希代码。Returns the hash code for this instance.

(继承自 Attribute)

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)

在派生类中重写时,指示此实例的值是否是派生类的默认值。When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.

(继承自 Attribute)

当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(继承自 Attribute)

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)


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

将一组名称映射为对应的一组调度标识符。Maps a set of names to a corresponding set of dispatch identifiers.

(继承自 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。Retrieves the type information for an object, which can be used to get the type information for an interface.

(继承自 Attribute)

检索对象提供的类型信息接口的数量(0 或 1)。Retrieves the number of type information interfaces that an object provides (either 0 or 1).

(继承自 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供对某一对象公开的属性和方法的访问。Provides access to properties and methods exposed by an object.

(继承自 Attribute)