See Also: WebPermission Members
System.Net.WebPermission provides a set of methods and properties to control access to Internet resources. You can use a System.Net.WebPermission to provide either restricted or unrestricted access to your resource, based on the System.Security.Permissions.PermissionState that is set when the System.Net.WebPermission is created.
Create a System.Net.WebPermission instance by calling its constructor using one of the following sets of parameters:
No parameters. The default System.Security.Permissions.PermissionState is System.Security.Permissions.PermissionState.None.
A System.Security.Permissions.PermissionState. Specify either System.Security.Permissions.PermissionState.Unrestricted to allow any URI to be used in the target class, or System.Security.Permissions.PermissionState.None to allow access only to URIs that you specify through the use of the WebPermission.AddPermission(NetworkAccess, string) method.
A System.Net.NetworkAccess value and a URI string. The specified URI has permissions granted by the System.Net.NetworkAccess value.
A System.Net.NetworkAccess specifier and URI regular expression.
The WebPermission.ConnectList and WebPermission.AcceptList hold the URIs to which you have granted access permission. To add a URI to either of these lists, use WebPermission.AddPermission(NetworkAccess, string). If you pass NetworkAccess.Accept as the System.Net.NetworkAccess parameter, the URI will be added to the WebPermission.AcceptList. System.Net.WebPermission will allow connections to your target class with URIs matching the WebPermission.AcceptList.
To deny access to an Internet resource, you must deny access to all the possible paths to that resource. This requires calling WebPermission.#ctor(System.Security.Permissions.PermissionState) with state parameter set to System.Security.CodeAccessPermission.Deny. A better approach is to allow access to the specific resource only. For more information about this subject, refer to the [<topic://cpcondeny>] topic.
You need to deny access using only the resource canonical path. There is no need to use all the path's syntactical variations.
User name and default port information is stripped from the Uri before the comparison with the regular expression argument that is supplied to the WebPermission.#ctor(NetworkAccess, System.Text.RegularExpressions.Regex) constructor. If the regular expression contains user information or the default port number, then all incoming Uris will fail to match the regular expression.