[Serializable] |
Create a WebPermission instance by calling its constructor using one of the following sets of parameters:
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. If you pass NetworkAccess.Accept as the NetworkAccess parameter, the URI will be added to the WebPermission.AcceptList. WebPermission will allow connections to your target class with URIs matching the WebPermission.AcceptList.
ctor #1 | Overloaded:.ctor() Default constructor. This constructor is called by derived class constructors to initialize state in this type.Creates a new instance of the WebPermission class. |
ctor #2 | Overloaded:.ctor(PermissionState state) Creates a new instance of the WebPermission class that passes all demands or fails all demands. |
ctor #3 | Overloaded:.ctor(NetworkAccess access, Regex uriRegex) Initializes a new instance of the WebPermission class with the specified access rights for the specified URI regular expression. |
ctor #4 | Overloaded:.ctor(NetworkAccess access, string uriString) Initializes a new instance of the WebPermission class with the specified access rights for the specified URI. |
AcceptList | Read-only This property returns an enumeration of a single accept permissions held by this WebPermission. The possible objects types contained in the returned enumeration are String and Regex. |
ConnectList | Read-only This property returns an enumeration of a single connect permissions held by this WebPermission. The possible objects types contained in the returned enumeration are String and Regex. |
AddPermission | Overloaded:AddPermission(NetworkAccess access, Regex uriRegex) Adds the specified URI with the specified access rights to the current WebPermission. |
AddPermission | Overloaded:AddPermission(NetworkAccess access, string uriString) Adds the specified URI string with the specified access rights to the current WebPermission. |
Assert (inherited from System.Security.CodeAccessPermission) |
See base class member description: System.Security.CodeAccessPermission.Assert Asserts that calling code can access the resource identified by the current permission through the code that calls this method, even if callers higher in the stack have not been granted permission to access the resource. |
Copy | Overridden: Creates a copy of a WebPermission. |
Demand (inherited from System.Security.CodeAccessPermission) |
See base class member description: System.Security.CodeAccessPermission.Demand Forces a SecurityException at run time if all callers higher in the call stack have not been granted the permission specified by the current instance. |
Deny (inherited from System.Security.CodeAccessPermission) |
See base class member description: System.Security.CodeAccessPermission.Deny Prevents callers higher in the call stack from using the code that calls this method to access the resource specified by the current instance. |
Equals (inherited from System.Object) |
See base class member description: System.Object.Equals Derived from System.Object, the primary base class for all objects. |
FromXml | Overridden: Reconstructs a WebPermission from an XML encoding. |
GetHashCode (inherited from System.Object) |
See base class member description: System.Object.GetHashCode Derived from System.Object, the primary base class for all objects. |
GetType (inherited from System.Object) |
See base class member description: System.Object.GetType Derived from System.Object, the primary base class for all objects. |
Intersect | Overridden: Returns the logical intersection of two WebPermission s. |
IsSubsetOf | Overridden: Determines whether the current WebPermission is a subset of the specified object. |
IsUnrestricted | Checks the overall permission state of the WebPermission. |
PermitOnly (inherited from System.Security.CodeAccessPermission) |
See base class member description: System.Security.CodeAccessPermission.PermitOnly 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. |
ToString (inherited from System.Security.CodeAccessPermission) |
See base class member description: System.Security.CodeAccessPermission.ToString Creates and returns a string representation of the current permission object. |
ToXml | Overridden: Creates an XML encoding of a WebPermission and its current state. |
Union | Overridden: Returns the logical union between two instances of the WebPermission class. |
Finalize (inherited from System.Object) |
See base class member description: System.Object.Finalize Derived from System.Object, the primary base class for all objects. |
MemberwiseClone (inherited from System.Object) |
See base class member description: System.Object.MemberwiseClone Derived from System.Object, the primary base class for all objects. |
Hierarchy:
public WebPermission(); |
public WebPermission( |
state
// Creates a 'WebPermission'. WebPermission myWebPermission1 = new WebPermission(PermissionState.None); // Allows access to the first set of URL's. myWebPermission1.AddPermission(NetworkAccess.Connect,"http://www.microsoft.com"); myWebPermission1.AddPermission(NetworkAccess.Connect,"http://www.msn.com"); // Checks whether all callers higher in the call stack have been granted the permissionor not. myWebPermission1.Demand();
public WebPermission( |
access
uriRegex
// Creates an instance of 'Regex' that accepts all URL's containing the host fragment 'www.contoso.com'. Regex myRegex = new Regex("http://www.contoso.com/*"); // Creates a 'WebPermission' that gives the permissions to all the hosts containing same host fragment. WebPermission myWebPermission = new WebPermission(NetworkAccess.Connect,myRegex); myWebPermission.AddPermission(NetworkAccess.Connect,"http://www.contoso.com/Servers"); myWebPermission.AddPermission(NetworkAccess.Connect,"http://www.contoso.com/windows"); myWebPermission.AddPermission(NetworkAccess.Connect,"http://www.contoso.com/office"); // Checks all callers higher in the call stack have been granted the permission. myWebPermission.Demand();
public WebPermission( |
access
uriString
// Creates a WebPermission. WebPermission myWebPermission1 = new WebPermission(NetworkAccess.Connect,"http://www.contoso.com"); myWebPermission1.Demand();
public IEnumerator AcceptList {get;}
|
// Get all URI's with Accept permission. IEnumerator myEnum1 = myWebPermission1.AcceptList; Console.WriteLine("\n\nThe URIs with Accept permission are :\n"); while (myEnum1.MoveNext()) Console.WriteLine("\tThe URI is : "+myEnum1.Current);
public IEnumerator ConnectList {get;}
|
// Gets all URIs with Connect permission. IEnumerator myEnum = myWebPermission1.ConnectList; Console.WriteLine("\nThe URIs with Connect permission are :\n"); while (myEnum.MoveNext()) Console.WriteLine("\tThe URI is : "+myEnum.Current);
public void AddPermission( |
access
uriRegex
Exception Type | Condition |
---|---|
ArgumentNullException | The uriRegex parameter is null. |
// Creates a WebPermission. WebPermission myWebPermission1 = new WebPermission(); // Allows Connect access to the specified URLs. myWebPermission1.AddPermission(NetworkAccess.Connect,"http://www.contoso.com"); myWebPermission1.AddPermission(NetworkAccess.Connect,"http://www.adventure-works.com"); myWebPermission1.AddPermission(NetworkAccess.Connect,"http://www.alpineskihouse.com"); // Creates a Regex with the www.contoso.com host fragment as the regular expression. Regex myRegex = new Regex("http://www.contoso.com/*"); // Allows access to the set of URLs that contain the regular expression myRegex. myWebPermission1.AddPermission(NetworkAccess.Connect,myRegex); myWebPermission1.Demand();
public void AddPermission( |
access
uriString
Exception Type | Condition |
---|---|
ArgumentNullException | uriString is null. |
// Allows access to a set of resources. myWebPermission1.AddPermission(NetworkAccess.Connect,"http://www.contoso.com"); myWebPermission1.AddPermission(NetworkAccess.Connect,"http://www.adventure-works.com"); // Checks whether all callers higher in the call stack have been granted the permissionor. myWebPermission1.Demand();
public void Assert(); |
Exception Type | Condition |
---|---|
SecurityException | The calling code does not have SecurityPermissionFlag.Assertion. -or- There is already an active CodeAccessPermission.Assert for the current frame. |
The call to CodeAccessPermission.Assert is effective until the calling code returns to its caller. Only one CodeAccessPermission.Assert can be active on a frame. An attempt to call CodeAccessPermission.Assert when an active CodeAccessPermission.Assert exists on the frame results in a SecurityException. Call CodeAccessPermission.RevertAssert or CodeAccessPermission.RevertAll to remove an active CodeAccessPermission.Assert.
CodeAccessPermission.Assert is ignored for a permission not granted because a demand for that permission will not succeed. However, if code lower on the call stack calls CodeAccessPermission.Demand for that permission, a SecurityException is thrown when the stack walk reaches the code that tried to call CodeAccessPermission.Assert. This happens because the code that called CodeAccessPermission.Assert has not been granted the permission, even though it tried to CodeAccessPermission.Assert it.
Because calling CodeAccessPermission.Assert removes the requirement that all code in the call chain must be granted permission to access the specified resource, it can open up security vulnerabilities if used incorrectly or inappropriately. Therefore, it should be used with great caution.
public override IPermission Copy(); |
// Creates another WebPermission instance that is the copy of the above WebPermission instance. WebPermission myWebPermission2 = (WebPermission) myWebPermission1.Copy(); // Checks whether all callers higher in the call stack have been granted the permissionor not. myWebPermission2.Demand();
public void Demand(); |
Exception Type | Condition |
---|---|
SecurityException | A caller higher in the call stack does not have the permission specified by the current instance. -or- A caller higher in the call stack has called CodeAccessPermission.Deny on the current permission object. |
The permissions of the code that calls this method are not examined; the check begins from the immediate caller of that code and proceeds up the stack. The call stack is typically represented as growing down, so that methods higher in the call stack call methods lower in the call stack. CodeAccessPermission.Demand succeeds only if no SecurityException is raised.
public void Deny(); |
Exception Type | Condition |
---|---|
SecurityException | There is already an active CodeAccessPermission.Deny for the current frame. |
CodeAccessPermission.Deny can limit the liability of the programmer or prevent accidental security vulnerabilities because it prevents the method that calls CodeAccessPermission.Deny from being used to access the resource protected by the denied permission. If a method calls CodeAccessPermission.Deny on a permission, and if a CodeAccessPermission.Demand for that permission is invoked by a caller lower in the call stack, that security check will fail when it reaches the CodeAccessPermission.Deny.
The call to CodeAccessPermission.Deny is effective until the calling code returns to its caller. Only one CodeAccessPermission.Deny can be active on a frame. An attempt to call CodeAccessPermission.Deny when an active CodeAccessPermission.Deny exists on the frame results in a SecurityException. Call CodeAccessPermission.RevertDeny or CodeAccessPermission.RevertAll to remove an active CodeAccessPermission.Deny. CodeAccessPermission.Deny is ignored for a permission not granted because a demand for that permission will not succeed.
~WebPermission(); |
public override void FromXml( |
securityElement
Exception Type | Condition |
---|---|
ArgumentNullException | The securityElement parameter is null |
ArgumentException | securityElement is not a permission element for this type. |
Use the WebPermission.ToXml method to XML-encode the WebPermission, including state information.
// Creates a WebPermission with no permission to the protected resource. WebPermission myWebPermission1 = new WebPermission(PermissionState.None); // Creates a SecurityElement by calling the ToXml method on WebPermission instance and // print its attributes which hold the XML encoding of the WebPermission. Console.WriteLine("Attributes and Values of the WebPermission are :"); PrintKeysAndValues(myWebPermission1.ToXml().Attributes); // Creates another WebPermission with no permission to the protected resource. WebPermission myWebPermission2 = new WebPermission(PermissionState.None); //Converts the new WebPermission from XML using myWebPermission1. myWebPermission2.FromXml(myWebPermission1.ToXml());
public virtual int GetHashCode(); |
public Type GetType(); |
public override IPermission Intersect( |
target
Exception Type | Condition |
---|---|
ArgumentException | target is not of type WebPermission |
This method overrides CodeAccessPermission.Intersect and is implemented to support the IPermission interface.
// Creates a third WebPermission instance by logical intersection of the first two WebPermission instances. WebPermission myWebPermission3 =(WebPermission) myWebPermission1.Intersect(myWebPermission2); Console.WriteLine("\nAttributes and Values of the WebPermission instance after the Intersect are:\n"); Console.WriteLine(myWebPermission3.ToXml().ToString());
public override bool IsSubsetOf( |
target
Exception Type | Condition |
---|---|
ArgumentException | the target parameter is not an instance of WebPermission. |
NotSupportedException | If the current instance contains a Regex-encoded right and there is not exactly same right found in the target instance. |
// Create the target permission. WebPermission targetPermission = new WebPermission(); targetPermission.AddPermission(NetworkAccess.Connect, new Regex("www\\.contoso\\.com/Public/*")); // Create the permission for a URI matching target. WebPermission connectPermission = new WebPermission(); connectPermission.AddPermission(NetworkAccess.Connect, "www.contoso.com/Public/default.htm"); //The following statement prints true. Console.WriteLine(connectPermission.IsSubsetOf(targetPermission));
public bool IsUnrestricted(); |
protected object MemberwiseClone(); |
public void PermitOnly(); |
Exception Type | Condition |
---|---|
SecurityException | There is already an active CodeAccessPermission.PermitOnly for the current frame. |
Call this method to ensure that your code can be used to access only the specified resources. The call to CodeAccessPermission.PermitOnly is effective until the calling code returns to its caller. Only one CodeAccessPermission.PermitOnly can be active on a frame. An attempt to call CodeAccessPermission.PermitOnly when an active CodeAccessPermission.PermitOnly exists on the frame results in a SecurityException. Call CodeAccessPermission.RevertPermitOnly or CodeAccessPermission.RevertAll to remove an active CodeAccessPermission.PermitOnly.
CodeAccessPermission.PermitOnly is ignored for a permission not granted because a demand for that permission will not succeed. However, if code lower on the call stack later calls CodeAccessPermission.Demand for that permission, a SecurityException is thrown when the stack walk reaches the code that tried to call CodeAccessPermission.PermitOnly. This is because the code that called CodeAccessPermission.PermitOnly has not been granted the permission, even though it called CodeAccessPermission.PermitOnly for that permission. The call stack is typically represented as growing down, so that methods higher in the call stack call methods lower in the call stack.
public override string ToString(); |
public override SecurityElement ToXml(); |
// Creates a WebPermission with no permission to the protected resource. WebPermission myWebPermission1 = new WebPermission(PermissionState.None); // Creates a SecurityElement by calling the ToXml method on WebPermission instance and // print its attributes which hold the XML encoding of the WebPermission. Console.WriteLine("Attributes and Values of the WebPermission are :"); PrintKeysAndValues(myWebPermission1.ToXml().Attributes); // Creates another WebPermission with no permission to the protected resource. WebPermission myWebPermission2 = new WebPermission(PermissionState.None); //Converts the new WebPermission from XML using myWebPermission1. myWebPermission2.FromXml(myWebPermission1.ToXml());
public override IPermission Union( |
target
// Creates another WebPermission that is the Union of the two WebPermission instances. WebPermission myWebPermission3 =(WebPermission) myWebPermission1.Union(myWebPermission2); Console.WriteLine("\nAttributes and values of the WebPermission after the Union are : "); // Displays the attributes,values and children. Console.WriteLine(myWebPermission3.ToXml().ToString());