Controls rights to access HTTP Internet resources.
Assembly: System (in System.dll)
Creates a new instance of theclass.
Initializes a new instance of theclass with the specified access rights for the specified URI regular expression.
Initializes a new instance of theclass with the specified access rights for the specified URI.
Creates a new instance of theclass that passes all demands or fails all demands.
Adds the specified URI with the specified access rights to the current.
Adds the specified URI string with the specified access rights to the current.
Declares that the calling code can access the resource protected by a permission demand through the code that calls this method, even if callers higher in the stack have not been granted permission to access the resource. Using Assert can create security issues.(Inherited from CodeAccessPermission.)
Creates a copy of a CodeAccessPermission.Copy().).(Overrides
Obsolete.Prevents callers higher in the call stack from using the code that calls this method to access the resource specified by the current instance.(Inherited from CodeAccessPermission.)
Reconstructs a CodeAccessPermission.FromXml(SecurityElement).)from an XML encoding.(Overrides
Returns the logical intersection of two CodeAccessPermission.Intersect(IPermission).)instances.(Overrides
Determines whether the current CodeAccessPermission.IsSubsetOf(IPermission).)is a subset of the specified object.(Overrides
Checks the overall permission state of the.
Prevents callers higher in the call stack from using the code that calls this method to access all resources except for the resource specified by the current instance.(Inherited from CodeAccessPermission.)
Creates and returns a string representation of the current permission object.(Inherited from CodeAccessPermission.)
Creates an XML encoding of a CodeAccessPermission.ToXml().)and its current state.(Overrides
Returns the logical union between two instances of the CodeAccessPermission.Union(IPermission).)class.(Overrides
PermissionState that is set when the is created.provides a set of methods and properties to control access to Internet resources. You can use a to provide either restricted or unrestricted access to your resource, based on the
Create ainstance by calling its constructor using one of the following sets of parameters:
A NetworkAccess specifier and URI regular expression.
The ConnectList and AcceptList hold the URIs to which you have granted access permission. To add a URI to either of these lists, use AddPermission. If you pass Accept as the NetworkAccess parameter, the URI will be added to the AcceptList. will allow connections to your target class with URIs matching the AcceptList.
To deny access to an Internet resource, you must deny access to all the possible paths to that resource. This requires calling WebPermission.WebPermission with state parameter set to Deny. A better approach is to allow access to the specific resource only. For more information about this subject, refer to the NIB: Using the Deny Method 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(NetworkAccess, 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.
The following example demonstrates how to create a new instance of Regex. Additional hosts are added to the connect and accept list of . Finally, the connect and accept list are displayed to the console.using a
' Create a Regex that accepts all the URLs contianing the host fragment www.contoso.com. Dim myRegex As New Regex("http://www\.contoso\.com/.*") ' Create a WebPermission that gives permission to all the hosts containing same host fragment. Dim myWebPermission As New WebPermission(NetworkAccess.Connect, myRegex) ' Add connect privileges for a www.adventure-works.com. myWebPermission.AddPermission(NetworkAccess.Connect, "http://www.adventure-works.com") ' Add accept privileges for www.alpineskihouse.com. myWebPermission.AddPermission(NetworkAccess.Accept, "http://www.alpineskihouse.com/") ' Check whether all callers higher in the call stack have been granted the permission. myWebPermission.Demand() ' Get all the URIs with Connect permission. Dim myConnectEnum As IEnumerator = myWebPermission.ConnectList Console.WriteLine(ControlChars.NewLine + "The 'URIs' with 'Connect' permission are :" + ControlChars.NewLine) While myConnectEnum.MoveNext() Console.WriteLine((ControlChars.Tab + myConnectEnum.Current.ToString())) End While ' Get all the URIs with Accept permission. Dim myAcceptEnum As IEnumerator = myWebPermission.AcceptList Console.WriteLine(ControlChars.NewLine + ControlChars.NewLine + "The 'URIs' with 'Accept' permission is :" + ControlChars.NewLine) While myAcceptEnum.MoveNext() Console.WriteLine((ControlChars.Tab + myAcceptEnum.Current)) End While
Available since 1.1
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.