WebPermission 构造函数

定义

创建 WebPermission 类的新实例。Creates a new instance of the WebPermission class.

重载

WebPermission()

创建 WebPermission 类的新实例。Creates a new instance of the WebPermission class.

WebPermission(PermissionState)

创建 WebPermission 类的新实例,该实例允许所有命令或禁止所有命令。Creates a new instance of the WebPermission class that passes all demands or fails all demands.

WebPermission(NetworkAccess, String)

使用指定 URI 的指定访问权限初始化 WebPermission 类的新实例。Initializes a new instance of the WebPermission class with the specified access rights for the specified URI.

WebPermission(NetworkAccess, Regex)

使用指定 URI 正则表达式的指定访问权限初始化 WebPermission 类的新实例。Initializes a new instance of the WebPermission class with the specified access rights for the specified URI regular expression.

WebPermission()

创建 WebPermission 类的新实例。Creates a new instance of the WebPermission class.

public:
 WebPermission();
public WebPermission ();
Public Sub New ()

注解

创建 WebPermission 类的新实例。Creates a new instance of the WebPermission class. 此构造函数创建一个没有授予任何权限的空权限。This constructor creates an empty permission that does not grant any rights.

另请参阅

WebPermission(PermissionState)

创建 WebPermission 类的新实例,该实例允许所有命令或禁止所有命令。Creates a new instance of the WebPermission class that passes all demands or fails all demands.

public:
 WebPermission(System::Security::Permissions::PermissionState state);
public WebPermission (System.Security.Permissions.PermissionState state);
new System.Net.WebPermission : System.Security.Permissions.PermissionState -> System.Net.WebPermission
Public Sub New (state As PermissionState)

参数

state
PermissionState

一个 PermissionState 值。A PermissionState value.

示例

下面的示例创建 WebPermission 的实例,并向特定 Url 提供访问权限。The following example creates an instance of WebPermission and gives access rights to specific URLs.

// Create a WebPermission instance.
WebPermission^ myWebPermission1 = gcnew WebPermission( PermissionState::None );

// Allow access to the first set of URL's.
myWebPermission1->AddPermission( NetworkAccess::Connect, "http://www.microsoft.com/default.htm" );
myWebPermission1->AddPermission( NetworkAccess::Connect, "http://www.msn.com" );

// Check whether all callers higher in the call stack have been granted the permissionor not.
myWebPermission1->Demand();
// Create a WebPermission instance.  
WebPermission myWebPermission1 = new WebPermission(PermissionState.None);

// Allow access to the first set of URL's.
myWebPermission1.AddPermission(NetworkAccess.Connect,"http://www.microsoft.com/default.htm");
myWebPermission1.AddPermission(NetworkAccess.Connect,"http://www.msn.com");

// Check whether all callers higher in the call stack have been granted the permissionor not.
myWebPermission1.Demand();

' Create a WebPermission instance.  
Dim myWebPermission1 As New WebPermission(PermissionState.None)

' Allow access to the first set of URL's.
myWebPermission1.AddPermission(NetworkAccess.Connect, "http://www.microsoft.com/default.htm")
myWebPermission1.AddPermission(NetworkAccess.Connect, "http://www.msn.com")

' Check whether all callers higher in the call stack have been granted the permissionor not.
myWebPermission1.Demand()

注解

state 参数的值是 PermissionState.NonePermissionState.Unrestricted,分别为所有安全变量生成完全限制或完全不受限制的访问。The value of the state parameter is either PermissionState.None or PermissionState.Unrestricted, respectively yielding fully restricted or fully unrestricted access to all security variables. 如果指定 PermissionState.None,则可以使用 AddPermission授予对单个 Uri 的访问权限。If you specify PermissionState.None, then you can give access to individual URIs using AddPermission.

另请参阅

WebPermission(NetworkAccess, String)

使用指定 URI 的指定访问权限初始化 WebPermission 类的新实例。Initializes a new instance of the WebPermission class with the specified access rights for the specified URI.

public:
 WebPermission(System::Net::NetworkAccess access, System::String ^ uriString);
public WebPermission (System.Net.NetworkAccess access, string uriString);
new System.Net.WebPermission : System.Net.NetworkAccess * string -> System.Net.WebPermission
Public Sub New (access As NetworkAccess, uriString As String)

参数

access
NetworkAccess

一个 NetworkAccess 值,指示向指定的 URI 授予哪种访问权限。A NetworkAccess value that indicates what kind of access to grant to the specified URI. Accept 指示允许应用程序在本地资源上接受来自 Internet 的连接。Accept indicates that the application is allowed to accept connections from the Internet on a local resource. Connect 指示允许应用程序连接到特定的 Internet 资源。Connect indicates that the application is allowed to connect to specific Internet resources.

uriString
String

向其授予访问权限的 URI 字符串。A URI string to which access rights are granted.

异常

uriStringnulluriString is null.

示例

下面的示例创建一个新实例,该实例具有指定 URI 的连接权限 WebPermissionThe following example creates a new instance of WebPermission with connect rights for the specified URI.

// Create a WebPermission::instance.
WebPermission^ myWebPermission1 = gcnew WebPermission( NetworkAccess::Connect,"http://www.contoso.com/default.htm" );
myWebPermission1->Demand();

// Create a WebPermission.instance.
WebPermission myWebPermission1 = new WebPermission(NetworkAccess.Connect,"http://www.contoso.com/default.htm");
myWebPermission1.Demand();

' Create a WebPermission.instance.
Dim myWebPermission1 As New WebPermission(NetworkAccess.Connect, "http://www.contoso.com/default.htm")
myWebPermission1.Demand()

注解

此构造函数初始化 WebPermission,并向其授予目标权限以建立远程主机连接,或使用 uriString 参数描述的 URI 接受远程主机连接。This constructor initializes a WebPermission and grants its target permission to either make a remote host connection or accept a remote host connection using the URI described by the uriString parameter.

另请参阅

WebPermission(NetworkAccess, Regex)

使用指定 URI 正则表达式的指定访问权限初始化 WebPermission 类的新实例。Initializes a new instance of the WebPermission class with the specified access rights for the specified URI regular expression.

public:
 WebPermission(System::Net::NetworkAccess access, System::Text::RegularExpressions::Regex ^ uriRegex);
public WebPermission (System.Net.NetworkAccess access, System.Text.RegularExpressions.Regex uriRegex);
new System.Net.WebPermission : System.Net.NetworkAccess * System.Text.RegularExpressions.Regex -> System.Net.WebPermission
Public Sub New (access As NetworkAccess, uriRegex As Regex)

参数

access
NetworkAccess

一个 NetworkAccess 值,指示向指定的 URI 授予哪种访问权限。A NetworkAccess value that indicates what kind of access to grant to the specified URI. Accept 指示允许应用程序在本地资源上接受来自 Internet 的连接。Accept indicates that the application is allowed to accept connections from the Internet on a local resource. Connect 指示允许应用程序连接到特定的 Internet 资源。Connect indicates that the application is allowed to connect to specific Internet resources.

uriRegex
Regex

一个正则表达式,描述要对其授予访问权限的 URI。A regular expression that describes the URI to which access is to be granted.

示例

下面的示例使用指定的 System.Text.RegularExpressions.Regex的连接权限创建 WebPermission 的新实例。The following example creates a new instance of WebPermission with connect rights for the specified System.Text.RegularExpressions.Regex.

// Create an instance of 'Regex' that accepts all URL's containing the host
// fragment 'www.contoso.com'.
Regex^ myRegex = gcnew Regex( "http://www.contoso.com/.*" );

// Create a WebPermission that gives the permissions to all the hosts containing
// the same fragment.
WebPermission^ myWebPermission = gcnew WebPermission( NetworkAccess::Connect,myRegex );

// Checks all callers higher in the call stack have been granted the permission.
myWebPermission->Demand();

 // Create an instance of 'Regex' that accepts all  URL's containing the host 
 // fragment 'www.contoso.com'.
 Regex myRegex = new Regex(@"http://www\.contoso\.com/.*");

// Create a WebPermission that gives the permissions to all the hosts containing 
// the same fragment.
WebPermission myWebPermission = new WebPermission(NetworkAccess.Connect,myRegex);
   
// Checks all callers higher in the call stack have been granted the permission.
myWebPermission.Demand();
 
'  Creates an instance of 'Regex' that accepts all  URL's containing the host fragment 'www.contoso.com'.
Dim myRegex As New Regex("http://www\.contoso\.com/.*")
  
   ' Creates a 'WebPermission' that gives the permissions to all the hosts containing same host fragment.
   Dim myWebPermission As New WebPermission(NetworkAccess.Connect, myRegex)
   
  '  Checks all callers higher in the call stack have been granted the permission.
  myWebPermission.Demand()

注解

此构造函数初始化 WebPermission,并向其授予目标权限以建立远程主机连接,或使用 uriRegex 参数描述的 URI 接受远程主机连接。This constructor initializes a WebPermission and grants its target permission to either make a remote host connection or accept a remote host connection using the URI described by the uriRegex parameter.

备注

建议使用 RegexOptions.IgnoreCaseRegexOptions.CompiledRegexOptions.Singleline 标志创建 uriRegexIt is recommended that you create uriRegex using the RegexOptions.IgnoreCase, RegexOptions.Compiled, and RegexOptions.Singleline flags.

备注

可通过两种方式对照相关正则表达式列表(AcceptListConnectList)检查候选 URI 字符串。A candidate URI string is checked against the list of relevant regular expressions (AcceptList or ConnectList) in two ways. 首先,根据相应的列表检查候选 URI 字符串;如果没有匹配项,则将候选 URI 字符串转换为 Uri 并根据相应的列表进行检查。First, the candidate URI string is checked against the appropriate list; then, if there is no match, the candidate URI string is converted into a Uri and checked against the appropriate list.

另请参阅

适用于