Namespace: System.Net.Sockets
Assembly: System.dll
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.
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.
public SocketPermission(PermissionState state);
Initializes a new instance of the SocketPermission class with the specified permission state.
state: A PermissionState enumeration value that indicates whether the permission is unrestricted or fully restricted.public SocketPermission(SocketPermissionEntry[] permissionAccessEntries);
Initializes a new instance of the SocketPermission class with the specified array of SocketPermissionEntry objects.
permissionAccessEntries: An array of SocketPermissionEntry objects that grant or deny access to network resources.public void AcceptDomain();
Adds a network address to the set of allowed remote network addresses.
public void AddPermission(SocketPermission permission);
Adds a SocketPermission object to the current SocketPermission object.
public IPermission Copy();
Creates and returns an identical copy of the current permission object.
public void FromXml(SecurityElement element);
Reconstructs a security object with a specified state from an XML encoding.
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.
public IPermission Intersect(IPermission target);
Creates and returns a new permission that represents the intersection of the current permission and the specified permission.
public bool IsSubsetOf(IPermission target);
Determines whether the current permission is a subset of the specified permission.
public bool IsUnrestricted();
Indicates whether the permission is unrestricted.
public bool IsWellKnownPermissionId(int id);
Determines whether the specified id corresponds to a well-known permission type.
public IPermission ToUnion(IPermission target);
Creates and returns a new permission that represents the union of the current permission and the specified permission.