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. 通常情况下在托管库 (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

获取或设置针对其授予路径发现权限的文件或目录。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 的浅表副本。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)

将一组名称映射为对应的一组调度标识符。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)

适用于

另请参阅