WebPermission.AddPermission Method

Definition

Adds the specified URI with the specified access rights to the current WebPermission.

Overloads

AddPermission(NetworkAccess, String)

Adds the specified URI string with the specified access rights to the current WebPermission.

AddPermission(NetworkAccess, Regex)

Adds the specified URI with the specified access rights to the current WebPermission.

AddPermission(NetworkAccess, String)

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

Adds 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)

Parameters

access
NetworkAccess

A NetworkAccess that specifies the access rights that are granted to the URI.

uriString
String

A string that describes the URI to which access rights are granted.

Exceptions

uriString is null.

Examples

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

Remarks

If you have specified None as the PermissionState, use AddPermission to permit the use of uriString in the target class. The way that uriString can be used by the target class is specified by access. 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.

Note

Calling AddPermission on UnrestrictedWebPermission will have no effect, because permission is granted to all URIs.

Note

A candidate URI string is checked against the list of relevant regular expressions (AcceptList or ConnectList) in two ways. 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.

See also

Applies to

AddPermission(NetworkAccess, Regex)

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

Adds 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)

Parameters

access
NetworkAccess

A NetworkAccess that specifies the access rights that are granted to the URI.

uriRegex
Regex

A regular expression that describes the set of URIs to which access rights are granted.

Exceptions

The uriRegex parameter is null.

Examples

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

Remarks

If you have specified None as the PermissionState, use AddPermission to allow the use of uriRegex in the target class. 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.

Note

Calling AddPermission on an UnrestrictedWebPermission instance will have no effect as permission is granted to all URIs.

Note

It is recommended that you create uriRegex using the RegexOptions.IgnoreCase, RegexOptions.Compiled, and RegexOptions.Singleline flags.

Note

A candidate URI string is checked against the list of relevant regular expressions (AcceptList or ConnectList) in two ways. 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.

See also

Applies to