SocketPermission Class

Namespace: System.Net.Sockets

Assembly: System.dll

Summary

Controls access to the network for Socket operations. This class is part of the .NET Framework's security model and is less commonly used in modern .NET Core/.NET 5+ applications where security is managed through other mechanisms.

Remarks

The SocketPermission class defines a set of access rights that allow or deny network operations. It's primarily used in code access security (CAS) environments to restrict the permissions of code running with different security levels.

In .NET Core and later versions, the explicit use of SocketPermission for granular network access control is generally replaced by other security practices, such as operating system-level firewalls, sandboxing, and platform-specific security features.

If you are working with legacy .NET Framework applications, you might encounter this class. For newer applications, focus on standard security practices for network communication.

Constructors

SocketPermission(PermissionState)

public SocketPermission(PermissionState state);

Initializes a new instance of the SocketPermission class with the specified permission state.

Parameters

SocketPermission(SocketPermissionEntry[])

public SocketPermission(SocketPermissionEntry[] permissionAccessEntries);

Initializes a new instance of the SocketPermission class with the specified array of SocketPermissionEntry objects.

Parameters

Methods

AcceptDomain

public void AcceptDomain();

Adds a network address to the set of allowed remote network addresses.

AddPermission

public void AddPermission(SocketPermission permission);

Adds a SocketPermission object to the current SocketPermission object.

Copy

public IPermission Copy();

Creates and returns an identical copy of the current permission object.

FromXml

public void FromXml(SecurityElement element);

Reconstructs a security object with a specified state from an XML encoding.

GetCASXml

public SecurityElement GetCASXml();

Returns an XML encoding of the security object that can be used to create and initialize a security object with the same state.

Intersect

public IPermission Intersect(IPermission target);

Creates and returns a new permission that represents the intersection of the current permission and the specified permission.

IsSubsetOf

public bool IsSubsetOf(IPermission target);

Determines whether the current permission is a subset of the specified permission.

IsUnrestricted

public bool IsUnrestricted();

Indicates whether the permission is unrestricted.

IsWellKnownPermissionId

public bool IsWellKnownPermissionId(int id);

Determines whether the specified id corresponds to a well-known permission type.

ToUnion

public IPermission ToUnion(IPermission target);

Creates and returns a new permission that represents the union of the current permission and the specified permission.

See Also