WebPermission.AddPermission 方法

定义

将具有指定访问权限的指定 URI 添加到当前 WebPermissionAdds the specified URI with the specified access rights to the current WebPermission.

重载

AddPermission(NetworkAccess, String)

将具有指定访问权限的指定 URI 字符串添加到当前 WebPermissionAdds the specified URI string with the specified access rights to the current WebPermission.

AddPermission(NetworkAccess, Regex)

将具有指定访问权限的指定 URI 添加到当前 WebPermissionAdds the specified URI with the specified access rights to the current WebPermission.

AddPermission(NetworkAccess, String)

将具有指定访问权限的指定 URI 字符串添加到当前 WebPermissionAdds the specified URI string with the specified access rights to the current WebPermission.

public:
 void AddPermission(System::Net::NetworkAccess access, System::String ^ uriString);
public void AddPermission (System.Net.NetworkAccess access, string uriString);
member this.AddPermission : System.Net.NetworkAccess * string -> unit
Public Sub AddPermission (access As NetworkAccess, uriString As String)

参数

access
NetworkAccess

指定授予 URI 的访问权限的 NetworkAccessA NetworkAccess that specifies the access rights that are granted to the URI.

uriString
String

一个字符串,描述向其授予访问权限的 URI。A string that describes the URI to which access rights are granted.

异常

uriStringnulluriString is null.

示例

下面的示例演示如何将访问权限添加到特定 URL 字符串。The following example demonstrates how to add access rights to particular URL strings.

// Allow access to the first set of resources.
myWebPermission1->AddPermission( NetworkAccess::Connect, "http://www.contoso.com/default.htm" );
myWebPermission1->AddPermission( NetworkAccess::Connect, "http://www.adventure-works.com/default.htm" );

// Check whether if the callers higher in the call stack have been granted
// access permissions.
myWebPermission1->Demand();

  // Allow access to the first set of resources.
  myWebPermission1.AddPermission(NetworkAccess.Connect,"http://www.contoso.com/default.htm");
  myWebPermission1.AddPermission(NetworkAccess.Connect,"http://www.adventure-works.com/default.htm");

  // Check whether if the callers higher in the call stack have been granted 
  // access permissions.
  myWebPermission1.Demand();

' Allow access to the first set of resources.
myWebPermission1.AddPermission(NetworkAccess.Connect, "http://www.contoso.com/default.htm")
myWebPermission1.AddPermission(NetworkAccess.Connect, "http://www.adventure-works.com/default.htm")

' Check whether if the callers higher in the call stack have been granted 
' access permissions.
myWebPermission1.Demand()

注解

如果已指定 None 作为 PermissionState,请使用 AddPermission 允许在目标类中使用 uriStringIf you have specified None as the PermissionState, use AddPermission to permit the use of uriString in the target class. 目标类可使用 uriString 的方式由 access指定。The way that uriString can be used by the target class is specified by access. 指定 Accept 作为访问参数,将 uriString 参数指定的 URI 添加到 URI 接受字符串列表,或指定 Connect 作为访问参数,以将 URI 添加到 URI 连接字符串列表。Specify Accept as the access parameter to add the URI specified by the uriString parameter to the list of URI accept strings, or specify Connect as the access parameter to add the URI to the list of URI connect strings.

备注

UnrestrictedWebPermission 调用 AddPermission 将不起任何作用,因为授予所有 Uri 的权限。Calling AddPermission on UnrestrictedWebPermission will have no effect, because permission is granted to all URIs.

备注

可通过两种方式对照相关正则表达式列表(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.

另请参阅

AddPermission(NetworkAccess, Regex)

将具有指定访问权限的指定 URI 添加到当前 WebPermissionAdds the specified URI with the specified access rights to the current WebPermission.

public:
 void AddPermission(System::Net::NetworkAccess access, System::Text::RegularExpressions::Regex ^ uriRegex);
public void AddPermission (System.Net.NetworkAccess access, System.Text.RegularExpressions.Regex uriRegex);
member this.AddPermission : System.Net.NetworkAccess * System.Text.RegularExpressions.Regex -> unit
Public Sub AddPermission (access As NetworkAccess, uriRegex As Regex)

参数

access
NetworkAccess

一个 NetworkAccess,指定授予 URI 的访问权限。A NetworkAccess that specifies the access rights that are granted to the URI.

uriRegex
Regex

一个正则表达式,描述向其授予访问权限的 URI 集。A regular expression that describes the set of URIs to which access rights are granted.

异常

uriRegex 参数为 nullThe uriRegex parameter is null.

示例

下面的示例使用 AddPermission 为指定的 URI 提供访问权限。The following example uses AddPermission to give access rights for the specified URI.

// Create a WebPermission.
WebPermission^ myWebPermission1 = gcnew WebPermission;

// Allow Connect access to the specified URLs.
myWebPermission1->AddPermission( NetworkAccess::Connect, gcnew Regex( "http://www\\.contoso\\.com/.*",
   (RegexOptions)(RegexOptions::Compiled | RegexOptions::IgnoreCase | RegexOptions::Singleline) ) );

myWebPermission1->Demand();
// Create a WebPermission.
WebPermission myWebPermission1 = new WebPermission();

// Allow Connect access to the specified URLs.
myWebPermission1.AddPermission(NetworkAccess.Connect,new Regex("http://www\\.contoso\\.com/.*", 
  RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline));
 
myWebPermission1.Demand();

' Create a WebPermission.
Dim myWebPermission1 As New WebPermission()

' Allow Connect access to the specified URLs.
myWebPermission1.AddPermission(NetworkAccess.Connect, New Regex("http://www\.contoso\.com/.*", RegexOptions.Compiled Or RegexOptions.IgnoreCase Or RegexOptions.Singleline))

myWebPermission1.Demand()

注解

如果已指定 None 作为 PermissionState,请使用 AddPermission 允许在目标类中使用 uriRegexIf you have specified None as the PermissionState, use AddPermission to allow the use of uriRegex in the target class. 指定 Accept 作为 access 参数,将 uriRegex 参数指定的 URI 添加到 URI 接受字符串列表,或指定 Connect 作为访问参数,以将 URI 添加到 URI 连接字符串列表。Specify Accept as the access parameter to add the URI specified by the uriRegex parameter to the list of URI accept strings, or specify Connect as the access parameter to add the URI to the list of URI connect strings.

备注

UnrestrictedWebPermission 实例调用 AddPermission 将不会产生任何影响。Calling AddPermission on an UnrestrictedWebPermission instance will have no effect as permission is granted to all URIs.

备注

建议使用 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.

另请参阅

适用于