WebPermission 构造函数

定义

创建 WebPermission 类的新实例。

重载

WebPermission()

创建 WebPermission 类的新实例。

WebPermission(PermissionState)

创建 WebPermission 类的新实例,该实例允许所有命令或禁止所有命令。

WebPermission(NetworkAccess, String)

使用指定 URI 的指定访问权限初始化 WebPermission 类的新实例。

WebPermission(NetworkAccess, Regex)

使用指定 URI 正则表达式的指定访问权限初始化 WebPermission 类的新实例。

WebPermission()

Source:
WebPermission.cs
Source:
WebPermission.cs
Source:
WebPermission.cs
Source:
WebPermission.cs

创建 WebPermission 类的新实例。

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

注解

创建 WebPermission 类的新实例。 此构造函数创建不授予任何权限的空权限。

另请参阅

适用于

WebPermission(PermissionState)

Source:
WebPermission.cs
Source:
WebPermission.cs
Source:
WebPermission.cs
Source:
WebPermission.cs

创建 WebPermission 类的新实例,该实例允许所有命令或禁止所有命令。

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 值。

示例

以下示例创建 的 WebPermission 实例,并授予对特定 URL 的访问权限。

// 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()

注解

参数PermissionState.Nonestate值为 或 PermissionState.Unrestricted,分别产生对所有安全变量的完全受限或完全不受限制的访问。 如果指定 PermissionState.None,则可以使用 AddPermission授予对单个 URI 的访问权限。

另请参阅

适用于

WebPermission(NetworkAccess, String)

Source:
WebPermission.cs
Source:
WebPermission.cs
Source:
WebPermission.cs
Source:
WebPermission.cs

使用指定 URI 的指定访问权限初始化 WebPermission 类的新实例。

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 授予哪种访问权限。 Accept 指示允许应用程序在本地资源上接受来自 Internet 的连接。 Connect 指示允许应用程序连接到特定的 Internet 资源。

uriString
String

向其授予访问权限的 URI 字符串。

例外

uriStringnull

示例

以下示例为指定的 URI 创建具有连接权限的 的新实例 WebPermission

// 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 建立远程主机连接或接受远程主机连接。

另请参阅

适用于

WebPermission(NetworkAccess, Regex)

Source:
WebPermission.cs
Source:
WebPermission.cs
Source:
WebPermission.cs
Source:
WebPermission.cs

使用指定 URI 正则表达式的指定访问权限初始化 WebPermission 类的新实例。

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 授予哪种访问权限。 Accept 指示允许应用程序在本地资源上接受来自 Internet 的连接。 Connect 指示允许应用程序连接到特定的 Internet 资源。

uriRegex
Regex

一个正则表达式,描述要对其授予访问权限的 URI。

示例

以下示例为指定的 System.Text.RegularExpressions.Regex创建具有连接权限的 的新实例WebPermission

// 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 建立远程主机连接或接受远程主机连接。

注意

建议使用 RegexOptions.IgnoreCaseRegexOptions.CompiledRegexOptions.Singleline 标志创建 uriRegex

注意

根据相关正则表达式列表检查候选 URI 字符串, (AcceptListConnectList) 两种方式。 首先,根据相应的列表检查候选 URI 字符串;然后,如果没有匹配项,则候选 URI 字符串将转换为 , Uri 并对照相应的列表进行检查。

另请参阅

适用于