MSDN Library

ApplicationTrustsCollection Class

Namespace: System.Net.Security
Assembly: System (in System.dll)

Represents a collection of ApplicationTrust objects. This class allows you to manage the application trust relationships on a computer. An application trust is a declaration that a specific application is trustworthy.

Syntax

public sealed class ApplicationTrustsCollection : ICollection, IEnumerable

Remarks

The ApplicationTrustsCollection class is used to store and retrieve ApplicationTrust objects. Each ApplicationTrust object represents the trust granted to a specific application, identified by its publisher. This collection is typically managed by the .NET Framework's Code Access Security (CAS) policy engine.

You can use this collection to:

Members

Properties

Name Description
Count Gets the number of ApplicationTrust objects in the collection.
IsSynchronized Gets a value indicating whether the collection is thread-safe.
SyncRoot Gets an object that can be used for synchronization.

Methods

Name Description
Add(ApplicationTrust) Adds an ApplicationTrust object to the collection.
Clear() Removes all ApplicationTrust objects from the collection.
CopyTo(Array, Int32) Copies the entire ApplicationTrustCollection to a compatible one-dimensional Array, starting at the specified index of the target array.
GetEnumerator() Returns an enumerator that iterates through the ApplicationTrustCollection.
Remove(ApplicationTrust) Removes the specified ApplicationTrust object from the collection.

Example

The following code example demonstrates how to retrieve and iterate through the application trusts on the current computer.

using System; using System.Net.Security; using System.Security.Policy; public class ApplicationTrustExample { public static void Main(string[] args) { try { // Get the application trusts collection ApplicationTrustsCollection trusts = TrustManager.ApplicationTrusts; Console.WriteLine($"Number of application trusts: {trusts.Count}"); // Iterate through each application trust foreach (ApplicationTrust trust in trusts) { Console.WriteLine($"--- Trust Entry ---"); Console.WriteLine($" Application Name: {trust.ApplicationName ?? "N/A"}"); Console.WriteLine($" Is Fully Trusted: {trust.IsFullyTrusted}"); Console.WriteLine($" Persisted: {trust.Persisted}"); if (trust.ApplicationVersion != null) { Console.WriteLine($" Application Version: {trust.ApplicationVersion}"); } if (trust.Publisher != null) { Console.WriteLine($" Publisher: {trust.Publisher}"); } Console.WriteLine(); } } catch (Exception ex) { Console.WriteLine($"An error occurred: {ex.Message}"); } } }