WebPermissionAttribute 类

定义

指定权限以访问 Internet 资源。Specifies permission to access Internet resources. 无法继承此类。This class cannot be inherited.

public ref class WebPermissionAttribute 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)]
[System.Serializable]
public sealed class WebPermissionAttribute : System.Security.Permissions.CodeAccessSecurityAttribute
type WebPermissionAttribute = class
    inherit CodeAccessSecurityAttribute
Public NotInheritable Class WebPermissionAttribute
Inherits CodeAccessSecurityAttribute
继承
属性

示例

下面的示例演示如何将 WebPermissionAttribute 应用于方法。The following example demonstrates how to apply WebPermissionAttribute to a method.

public:
   // Deny access to a specific resource by setting the ConnectPattern property.
   [method:WebPermission(SecurityAction::Deny,ConnectPattern="http://www.contoso.com/")]

   void Connect()
   {
      // Create a Connection.
      HttpWebRequest^ myWebRequest = (HttpWebRequest^)(WebRequest::Create( "http://www.contoso.com" ));
      Console::WriteLine( "This line should never be printed" );
   }

    // Deny access to a specific resource by setting the ConnectPattern property. 
   [WebPermission(SecurityAction.Deny, ConnectPattern=@"http://www\.contoso\.com/")]

public void Connect() 
     {
        // Create a Connection.  
        HttpWebRequest myWebRequest = (HttpWebRequest)WebRequest.Create("http://www.contoso.com");
        Console.WriteLine("This line should never be printed");
     }


' Deny access to a specific resource by setting the ConnectPattern property. 
<WebPermission(SecurityAction.Deny, ConnectPattern := "http://www\.contoso\.com/.*")> Public Sub Connect()

' Create a Connection.	 
Dim myWebRequest As HttpWebRequest = CType(WebRequest.Create("http://www.contoso.com"), HttpWebRequest)
Console.WriteLine("This line should never be printed")
   

注解

WebPermissionAttribute 允许以声明方式指定类可使用的 URI 字符串和正则表达式字符串。WebPermissionAttribute allows you to declaratively specify which URI strings and regular expression strings your class can use.

WebPermissionAttribute 中指定的安全信息存储在属性目标的元数据中,后者是应用 WebPermissionAttribute 的类。The security information specified in the WebPermissionAttribute is stored in the metadata of the attribute target, which is the class to which WebPermissionAttribute is applied. 系统将在运行时访问此信息。The system accesses this information at run time. 传递给构造函数的 System.Security.Permissions.SecurityAction 确定允许的 WebPermissionAttribute 目标。The System.Security.Permissions.SecurityAction passed to the constructor determines the allowable WebPermissionAttribute targets. 系统使用 CreatePermission 方法返回的 WebPermission 将属性目标的安全信息转换为存储在元数据中的可序列化窗体。The system uses the WebPermission returned by the CreatePermission method to convert the security information of the attribute target to a serializable form stored in metadata.

备注

WebPermissionAttribute 仅用于声明性安全WebPermissionAttribute is used only for Declarative Security. 对于命令性安全,请使用相应的 WebPermissionFor Imperative Security, use the corresponding WebPermission.

构造函数

WebPermissionAttribute(SecurityAction)

用指定可在此类上执行的安全操作的值初始化 WebPermissionAttribute 类的新实例。Initializes a new instance of the WebPermissionAttribute class with a value that specifies the security actions that can be performed on this class.

属性

Accept

获取或设置当前 WebPermissionAttribute 接受的 URI 字符串。Gets or sets the URI string accepted by the current WebPermissionAttribute.

AcceptPattern

获取或设置正则表达式模式,该正则表达式模式描述当前 WebPermissionAttribute 接受的 URI。Gets or sets a regular expression pattern that describes the URI accepted by the current WebPermissionAttribute.

Action

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

(继承自 SecurityAttribute)
Connect

获取或设置当前 WebPermissionAttribute 控制的 URI 连接字符串。Gets or sets the URI connection string controlled by the current WebPermissionAttribute.

ConnectPattern

获取或设置描述当前 WebPermissionAttribute 控制的 URI 连接的正则表达式模式。Gets or sets a regular expression pattern that describes the URI connection controlled by the current WebPermissionAttribute.

TypeId

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

(继承自 Attribute)
Unrestricted

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

(继承自 SecurityAttribute)

方法

CreatePermission()

创建并返回 WebPermission 类的新实例。Creates and returns a new instance of the WebPermission class.

Equals(Object)

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

(继承自 Attribute)
GetHashCode()

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

(继承自 Attribute)
GetType()

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

(继承自 Object)
IsDefaultAttribute()

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

(继承自 Attribute)
Match(Object)

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

(继承自 Attribute)
MemberwiseClone()

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

(继承自 Object)
ToString()

返回一个表示当前对象的 string。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)
_Attribute.GetTypeInfoCount(UInt32)

检索对象提供的类型信息接口的数量(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)

适用于