.NET API Reference

SocketPolicy Class

Represents a policy that controls cross-domain access to network resources. This class is primarily used in Silverlight and Flash applications to define security policies for network communication.

Namespace

System.Net.Sockets

Assembly

System.dll

Inheritance

Object
  ›  SocketPolicy

Remarks

The SocketPolicy class is crucial for establishing secure network communication between different domains. When an application needs to connect to a server on a different domain or port, the server typically responds with a SocketPolicy file. This file contains rules that dictate whether the connection is allowed based on the requesting domain and other security considerations.

In modern .NET development, especially with .NET Core and .NET 5+, the use cases for SocketPolicy are less common in typical web applications due to architectural shifts and browser security models. However, it remains relevant for scenarios involving specific cross-platform network communication protocols or legacy systems.

Methods

SocketPolicy() public SocketPolicy()

Initializes a new instance of the SocketPolicy class.

// Example usage:
SocketPolicy policy = new SocketPolicy();
Load(Stream) public static SocketPolicy Load(Stream stream)

Loads a SocketPolicy from the specified stream.

// Example usage:
// Assuming 'policyStream' is a valid Stream containing policy data
// SocketPolicy policy = SocketPolicy.Load(policyStream);
Save(Stream) public void Save(Stream stream)

Saves the current SocketPolicy to the specified stream.

// Example usage:
// SocketPolicy policy = new SocketPolicy();
// // ... configure policy ...
// using (Stream outputStream = File.OpenWrite("policy.xml"))
// {
//     policy.Save(outputStream);
// }

Properties

ClientAccessPolicies public IList<ClientAccessPolicy> ClientAccessPolicies { get; }

Gets a list of client access policies.

IsDomainPolicy public bool IsDomainPolicy { get; }

Gets a value indicating whether this policy is a domain policy.

IsRootPolicy public bool IsRootPolicy { get; }

Gets a value indicating whether this policy is a root policy.

Fields

This class has no public fields.

See Also

System.Net.Sockets Namespace
ClientAccessPolicy Class