System.Net.SocketPermissionAttribute Class

public sealed class SocketPermissionAttribute : CodeAccessSecurityAttribute

Base Types

Object
  Attribute
    SecurityAttribute
      CodeAccessSecurityAttribute
        SocketPermissionAttribute

Assembly

System

Library

Networking

Summary

Used to declaratively specify security actions to control socket connections.

Description

The properties of a SocketPermissionAttribute are required to have non-null values. Once set, the values of the properties cannot be changed.

[Note: The details of a socket connection are specified using the properties of the current instance. For example, to secure a socket connection to port 80, set the System.Net.SocketPermissionAttribute.Port property equal to "80".

The security information declared by a security attribute is stored in the metadata of the attribute target, and is accessed by the system at run-time. Security attributes are used for declarative security only. For imperative security, use the corresponding permission class, SocketPermission .

The allowable SocketPermissionAttribute targets are determined by the SecurityAction passed to the constructor.

]

Attributes

AttributeUsageAttribute(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Constructor | AttributeTargets.Method, AllowMultiple=true, Inherited=false)

See Also

System.Net Namespace

Members

SocketPermissionAttribute Constructors

SocketPermissionAttribute Constructor

SocketPermissionAttribute Methods

SocketPermissionAttribute.CreatePermission Method

SocketPermissionAttribute Properties

SocketPermissionAttribute.Access Property
SocketPermissionAttribute.Host Property
SocketPermissionAttribute.Port Property
SocketPermissionAttribute.Transport Property


SocketPermissionAttribute Constructor

public SocketPermissionAttribute(SecurityAction action);

Summary

Constructs and initializes a new instance of the SocketPermissionAttribute class with the specified SecurityAction value.

Parameters

action
A SecurityAction value.

See Also

System.Net.SocketPermissionAttribute Class, System.Net Namespace

SocketPermissionAttribute.CreatePermission Method

public override IPermission CreatePermission();

Summary

Returns a SocketPermission that contains the security information of the current instance.

Return Value

A SocketPermission object with the security information of the current instance.

Exceptions

Exception TypeCondition
ArgumentExceptionOne or more of the current instance's System.Net.SocketPermissionAttribute.Access, System.Net.SocketPermissionAttribute.Host, System.Net.SocketPermissionAttribute.Transport or System.Net.SocketPermissionAttribute.Port properties is null .

Description

[Note: This method overrides System.Security.Permissions.SecurityAttribute.CreatePermission.

Applications typically do not call this method; it is intended for use by the system.

The security information described by a security attribute is stored in the metadata of the attribute target, and is accessed by the system at run-time. The system uses the object returned by this method to convert the security information of the current instance into the form stored in metadata.

]

See Also

System.Net.SocketPermissionAttribute Class, System.Net Namespace

SocketPermissionAttribute.Access Property

public string Access { get; set; }

Summary

Gets or sets the network access method specified by the current instance.

Property Value

A String containing a network access method allowed by the current instance. Valid values are "Accept" and "Connect".

Exceptions

Exception TypeCondition
ArgumentExceptionSystem.Net.SocketPermissionAttribute.Access is being set and is not null .

Description

This property is write-once. Once this property has been set to a non-null value, attempts to set this property to new value cause a ArgumentException .

Valid values for this property correspond to NetworkAccess enumeration values.

See Also

System.Net.SocketPermissionAttribute Class, System.Net Namespace

SocketPermissionAttribute.Host Property

public string Host { get; set; }

Summary

Gets or sets the DNS host name or IP address specified by the current instance.

Property Value

A String containing a DNS host name or IP address.

Exceptions

Exception TypeCondition
ArgumentExceptionSystem.Net.SocketPermissionAttribute.Host is being set and is not null .

Description

This property is write-once. Once this property has been set to a non-null value, attempts to set this property to new value cause a ArgumentException.

See Also

System.Net.SocketPermissionAttribute Class, System.Net Namespace

SocketPermissionAttribute.Port Property

public string Port { get; set; }

Summary

Gets or sets the port specified by the current instance.

Property Value

A String containing a port number, or "All" or -1 to indicate all ports.

Exceptions

Exception TypeCondition
ArgumentExceptionSystem.Net.SocketPermissionAttribute.Port is being set and is not null .

Description

This property is write-once. Once this property has been set to a non-null value, attempts to set this property to new value cause a ArgumentException .

See Also

System.Net.SocketPermissionAttribute Class, System.Net Namespace

SocketPermissionAttribute.Transport Property

public string Transport { get; set; }

Summary

Gets or sets the transport type specified by the current instance.

Property Value

A String containing the transport type associated with the current instance. Valid values are "All", "Connectionless", "ConnectionOriented", "Tcp", and "Udp".

Exceptions

Exception TypeCondition
ArgumentExceptionSystem.Net.SocketPermissionAttribute.Transport is being set and is not null .

Description

This property is write-once. Once this property has been set to a non-null value, attempts to set this property to new value cause a ArgumentException .

[Note: Valid values for this property correspond to TransportType enumeration values.]

See Also

System.Net.SocketPermissionAttribute Class, System.Net Namespace