System.Net.SocketPermission Class

public class SocketPermission : CodeAccessPermission

Base Types

Object
  CodeAccessPermission
    SocketPermission

This type implements IPermission.

Assembly

System

Library

Networking

Summary

Secures socket connections.

Description

SocketPermission instances control permission to accept connections or initiate socket connections. A socket permission can secure access based on host name or IP address, a port number, and a transport protocol.

The XML encoding of a SocketPermission instance is defined below in EBNF format, in particular the following conventions are used:

The following meta-language symbols are used:

BuildVersion refers to the build version of the shipping CLI. This is a dotted build number such as '2412.0'.

ECMAPubKeyToken ::= b77a5c561934e089

HostName refers to a host name such as www.contoso.com .

Portnumber denotes a Int32 value indicating a port.

TransportProtocol ::= 1 | 2 | 3 /*1= UDP , 2 = TCP, 3 = both */

SocketPermissionXML::=

<IPermission class="

System.Net.SocketPermission,

System,

Version=1.0. BuildVersion,

Culture=neutral,

PublicKeyToken =ECMAPubKeyToken"

version="1"

(

Unrestricted="true"

)

|

&gt;

(<ConnectAccess>

(

<ENDPOINT> HostName# PortNumber# TransportProtocol</ENDPOINT>

)+

</ConnectAccess>

)

|

>

(<AcceptAccess>

(

<ENDPOINT> HostName# PortNumber# TransportProtocol</ENDPOINT>

)+

</AcceptAccess>

</IPermission>

)

|

/>

See Also

System.Net Namespace

Members

SocketPermission Constructors

SocketPermission(System.Security.Permissions.PermissionState) Constructor
SocketPermission(System.Net.NetworkAccess, System.Net.TransportType, System.String, int) Constructor

SocketPermission Methods

SocketPermission.Copy Method
SocketPermission.FromXml Method
SocketPermission.Intersect Method
SocketPermission.IsSubsetOf Method
SocketPermission.ToXml Method
SocketPermission.Union Method

SocketPermission Fields

SocketPermission.AllPorts Field


SocketPermission(System.Security.Permissions.PermissionState) Constructor

public SocketPermission(PermissionState state);

Summary

Constructs and initializes a new instance of the SocketPermission class with the specified PermissionState value.

Parameters

state
A PermissionState value.

Description

[Note: This constructor creates either fully restricted (System.Security.Permissions.PermissionState.None) or System.Security.Permissions.PermissionState.Unrestricted access to sockets.

]

See Also

System.Net.SocketPermission Class, System.Net Namespace

SocketPermission(System.Net.NetworkAccess, System.Net.TransportType, System.String, int) Constructor

public SocketPermission(NetworkAccess access, TransportType transport, string hostName, int portNumber);

Summary

Constructs and initializes a new instance of the SocketPermission class.

Parameters

access
A NetworkAccess value indicating the type of access to secure.
transport
A TransportType value indicating the transport type to secure. Specify System.Net.TransportType.All to create a permission that secures all transport types.
hostName
A String containing the host name for the transport address.
portNumber
A Int32 containing the port number for the transport address. Specify System.Net.SocketPermission.AllPorts create a permission that secures all ports.

Exceptions

Exception TypeCondition
ArgumentNullExceptionThe hostName parameter is null .

Description

No exception is thrown if the specified TransportType or NetworkAccess is invalid.

See Also

System.Net.SocketPermission Class, System.Net Namespace

SocketPermission.Copy Method

public override IPermission Copy();

Summary

Returns a new SocketPermission object containing the same values as the current instance.

Return Value

A new SocketPermission containing the same values as the current instance.

Description

[Note: The object returned by this method represents the same level of access as the current instance.

This method overrides System.Security.CodeAccessPermission.Copy and is implemented to support the IPermission interface.

]

See Also

System.Net.SocketPermission Class, System.Net Namespace

SocketPermission.FromXml Method

public override void FromXml(SecurityElement securityElement);

Summary

Reconstructs the state of a SocketPermission object using the specified XML encoding.

Parameters

securityElement
A SecurityElement instance containing the XML encoding used to reconstruct the state of a SocketPermission object.

Exceptions

Exception TypeCondition
ArgumentNullExceptionsecurityElement is null .

ArgumentExceptionsecurityElement is not a SocketPermission permission element.

Description

The state of the current instance is changed to the state encoded in securityElement.

[Note: For the XML schema for this class, see the SocketPermission class page.

This method overrides System.Security.CodeAccessPermission.FromXml(System.Security.SecurityElement).

]

See Also

System.Net.SocketPermission Class, System.Net Namespace

SocketPermission.Intersect Method

public override IPermission Intersect(IPermission target);

Summary

Returns a SocketPermission object that is the intersection of the current instance and the specified object.

Parameters

target
A SocketPermission instance to intersect with the current instance.

Return Value

A new SocketPermission instance that represents the intersection of the current instance and target. If target is null , returns null . If the intersection is empty, returns null . If the current instance is unrestricted, returns a copy of target. If target is unrestricted, returns a copy of the current instance.

Exceptions

Exception TypeCondition
ArgumentExceptiontarget is not of type SocketPermission .

Description

[Note: The intersection of two permissions is a permission that secures the resources and operations secured by both permissions. Specifically, it represents the minimum permission such that any demand that passes both permissions will also pass their intersection.

This method overrides System.Security.CodeAccessPermission.Intersect(System.Security.IPermission) and is implemented to support the IPermission interface.

]

See Also

System.Net.SocketPermission Class, System.Net Namespace

SocketPermission.IsSubsetOf Method

public override bool IsSubsetOf(IPermission target);

Summary

Determines whether the current instance is a subset of the specified object.

Parameters

target
A SocketPermission instance that is to be tested for the subset relationship.

Return Value

true if the current instance is a subset of target ; otherwise, false . If the current instance is unrestricted, and target is not, returns false . If target is unrestricted, returns true . If target is null and the current instance does not secure any resources and is not unrestricted, returns true .

Exceptions

Exception TypeCondition
ArgumentExceptiontarget is not null and is not of type SocketPermission.

Description

The subset relationship is true if every resource secured by the current instance is secured by target .

[Note: This method overrides System.Security.CodeAccessPermission.IsSubsetOf(System.Security.IPermission) and is implemented to support the IPermission interface.

]

See Also

System.Net.SocketPermission Class, System.Net Namespace

SocketPermission.ToXml Method

public override SecurityElement ToXml();

Summary

Returns the XML encoding of the current instance.

Return Value

A SecurityElement containing the XML encoding of the state of the current instance.

Description

[Note: For the XML schema for this class, see the SocketPermission class page.

This method overrides System.Security.CodeAccessPermission.ToXml .

]

See Also

System.Net.SocketPermission Class, System.Net Namespace

SocketPermission.Union Method

public override IPermission Union(IPermission target);

Summary

Returns a SocketPermission that is the union of the current instance and the specified object.

Parameters

target
A SocketPermission instance to combine with the current instance.

Return Value

A SocketPermission instance that represents the union of the current instance and target. If the current instance or target is unrestricted, returns a SocketPermission instance that is unrestricted.

Exceptions

Exception TypeCondition
ArgumentNullExceptiontarget is null .
ArgumentExceptiontarget is not of type SocketPermission .

Description

[Note: The result of a call to System.Net.SocketPermission.Union(System.Security.IPermission) is a permission that represents all of the access to socket connections represented by the current instance as well as the access represented by target. Any demand that passes either the current instance or target passes their union.

This method overrides System.Security.CodeAccessPermission.Union(System.Security.IPermission) and is implemented to support the IPermission interface.

]

See Also

System.Net.SocketPermission Class, System.Net Namespace

SocketPermission.AllPorts Field

public const int AllPorts = -1;

Summary

Defines a constant value that represents all ports.

This field is read-only. The value of this field is -1.

See Also

System.Net.SocketPermission Class, System.Net Namespace