SocketPermissionEntry Class
Namespace: System.Net
Assembly: System.dll
Represents a permission entry for the SocketPermission class. This class cannot be inherited.
Syntax
public sealed class SocketPermissionEntry
Constructors
| Name | Description |
|---|---|
SocketPermissionEntry(NetworkTransportPermission permission, string hostname, string port, int denyOnly) |
Initializes a new instance of the SocketPermissionEntry class with the specified permission, host name, port number, and security actions. |
SocketPermissionEntry(NetworkTransportPermission permission, string hostname, string port, string accept) |
Initializes a new instance of the SocketPermissionEntry class with the specified permission, host name, port number, and accept/connect permissions. |
Properties
| Name | Description |
|---|---|
HostName |
Gets the host name for this SocketPermissionEntry. |
Port |
Gets the port number for this SocketPermissionEntry. |
Permission |
Gets the permission state for this SocketPermissionEntry. |
Transport |
Gets the transport type for this SocketPermissionEntry. |
Remarks
Instances of the SocketPermissionEntry class are used by the SocketPermission class to define access control for network operations.
Each entry specifies a combination of transport protocol, host name, port, and the type of network access (accept or connect) that is allowed or denied.
Examples
The following example demonstrates how to create and use a SocketPermissionEntry.
using System;
using System.Net;
using System.Net.Sockets;
using System.Security.Permissions;
public class Example
{
public static void Main(string[] args)
{
// Create a SocketPermissionEntry to allow connecting to example.com on port 80
SocketPermissionEntry entry = new SocketPermissionEntry(
NetworkTransportPermission.Connect,
"example.com",
"80",
"Allow"
);
Console.WriteLine($"HostName: {entry.HostName}");
Console.WriteLine($"Port: {entry.Port}");
Console.WriteLine($"Permission: {entry.Permission}");
Console.WriteLine($"Transport: {entry.Transport}");
}
}