Επεξεργασία

Κοινή χρήση μέσω


WebPermission Constructors

Definition

Creates a new instance of the WebPermission class.

Overloads

WebPermission()

Creates a new instance of the WebPermission class.

WebPermission(PermissionState)

Creates a new instance of the WebPermission class that passes all demands or fails all demands.

WebPermission(NetworkAccess, String)

Initializes a new instance of the WebPermission class with the specified access rights for the specified URI.

WebPermission(NetworkAccess, Regex)

Initializes a new instance of the WebPermission class with the specified access rights for the specified URI regular expression.

WebPermission()

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

Creates a new instance of the WebPermission class.

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

Remarks

Creates a new instance of the WebPermission class. This constructor creates an empty permission that does not grant any rights.

See also

Applies to

WebPermission(PermissionState)

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

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)

Parameters

Examples

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

Remarks

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. If you specify PermissionState.None, then you can give access to individual URIs using AddPermission.

See also

Applies to

WebPermission(NetworkAccess, String)

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

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)

Parameters

access
NetworkAccess

A NetworkAccess value that indicates what kind of access to grant to the specified URI. Accept indicates that the application is allowed to accept connections from the Internet on a local resource. Connect indicates that the application is allowed to connect to specific Internet resources.

uriString
String

A URI string to which access rights are granted.

Exceptions

uriString is null.

Examples

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

Remarks

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.

See also

Applies to

WebPermission(NetworkAccess, Regex)

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

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)

Parameters

access
NetworkAccess

A NetworkAccess value that indicates what kind of access to grant to the specified URI. Accept indicates that the application is allowed to accept connections from the Internet on a local resource. Connect indicates that the application is allowed to connect to specific Internet resources.

uriRegex
Regex

A regular expression that describes the URI to which access is to be granted.

Examples

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

Remarks

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.

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