This documentation is archived and is not being maintained.

WebPermission Constructor (NetworkAccess, Regex)

.NET Framework 1.1

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

[Visual Basic]
Public Sub New( _
   ByVal access As NetworkAccess, _
   ByVal uriRegex As Regex _
)
[C#]
public WebPermission(
   NetworkAccess access,
 Regex uriRegex
);
[C++]
public: WebPermission(
   NetworkAccess access,
 Regex* uriRegex
);
[JScript]
public function WebPermission(
   access : NetworkAccess,
 uriRegex : Regex
);

Parameters

access
A NetworkAccess value indicating 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
A regular expression describing the URI to which acess is to be granted.

Remarks

This constructor initializes a WebPermission and grants its target permission to either make a remote host connection or to accept a remote host connection using the URI described by the uriRegex parameter.

Note   It is recommended to create uriRegex using the RegexOptions.IgnoreCase, RegexOptions.Compiled, and RegexOptions.Singleline flags.

Example

[Visual Basic, C#, C++] The following example creates a new instance of WebPermission with connect rights for the specified System.Text.RegularExpressions.Regex.

[Visual Basic] 
'  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()


[C#] 

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

[C++] 
// Create an instance of 'Regex' that accepts all  URL's containing the host
// fragment 'www.contoso.com'.
Regex* myRegex = new Regex(S"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();

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

WebPermission Class | WebPermission Members | System.Net Namespace | WebPermission Constructor Overload List | Regex

Show: