CertNameMappingCollection Class

Namespace: System.Net.Security

Summary

Represents a collection of CertNameMapping objects.

The CertNameMappingCollection class is used to manage a list of certificate name mappings. These mappings are used by the AuthenticationSchemes enumeration to associate specific certificate names with authentication protocols. This allows for fine-grained control over how client certificates are validated and used in network communications.

Syntax

public sealed class CertNameMappingCollection : System.Collections.CollectionBase
{
    // Constructors
    public CertNameMappingCollection();

    // Properties
    public CertNameMapping this[int index] { get; set; }
    public CertNameMapping this[string name] { get; }

    // Methods
    public int Add(CertNameMapping value);
    public void Clear();
    public bool Contains(CertNameMapping value);
    public void CopyTo(CertNameMapping[] array, int index);
    public IEnumerator GetEnumerator();
    public int IndexOf(CertNameMapping value);
    public void Insert(int index, CertNameMapping value);
    public void Remove(CertNameMapping value);
    public void RemoveAt(int index);
}
                
Members

Constructors

CertNameMappingCollection()

Initializes a new instance of the CertNameMappingCollection class.


public CertNameMappingCollection();
                

Properties

this[int index]

Gets or sets the CertNameMapping object at the specified index.


public CertNameMapping this[int index] { get; set; }
                
this[string name]

Gets the CertNameMapping object with the specified name.


public CertNameMapping this[string name] { get; }
                

Methods

Add(CertNameMapping value)

Appends a CertNameMapping object to the end of the collection.


public int Add(CertNameMapping value);
                
Clear()

Removes all CertNameMapping objects from the collection.


public void Clear();
                
Contains(CertNameMapping value)

Determines whether the collection contains the specified CertNameMapping object.


public bool Contains(CertNameMapping value);
                
CopyTo(CertNameMapping[] array, int index)

Copies the entire collection to a compatible one-dimensional array, starting at the specified index of the target array.


public void CopyTo(CertNameMapping[] array, int index);
                
GetEnumerator()

Returns an enumerator that iterates through the collection.


public IEnumerator GetEnumerator();
                
IndexOf(CertNameMapping value)

Returns the zero-based index of the first occurrence of the specified CertNameMapping object in the entire collection.


public int IndexOf(CertNameMapping value);
                
Insert(int index, CertNameMapping value)

Inserts a CertNameMapping object into the collection at the specified zero-based index.


public void Insert(int index, CertNameMapping value);
                
Remove(CertNameMapping value)

Removes the first occurrence of the specified CertNameMapping object from the collection.


public void Remove(CertNameMapping value);
                
RemoveAt(int index)

Removes the CertNameMapping object at the specified index from the collection.


public void RemoveAt(int index);
                
Example

The following example shows how to create a CertNameMappingCollection and add CertNameMapping objects to it.


using System;
using System.Net.Security;

public class Example
{
    public static void Main()
    {
        // Create a new CertNameMappingCollection
        CertNameMappingCollection mappings = new CertNameMappingCollection();

        // Create CertNameMapping objects
        CertNameMapping mapping1 = new CertNameMapping("CN=www.example.com", "Example.com");
        CertNameMapping mapping2 = new CertNameMapping("CN=*.anotherexample.org", "AnotherExample.org");

        // Add the mappings to the collection
        mappings.Add(mapping1);
        mappings.Add(mapping2);

        // Access a mapping by index
        CertNameMapping firstMapping = mappings[0];
        Console.WriteLine($"First mapping: CertName='{firstMapping.CertName}', MappedName='{firstMapping.MappedName}'");

        // Access a mapping by name (this relies on the MappedName for lookup)
        CertNameMapping accessedMapping = mappings["Example.com"];
        if (accessedMapping != null)
        {
            Console.WriteLine($"Accessed mapping by name: CertName='{accessedMapping.CertName}', MappedName='{accessedMapping.MappedName}'");
        }

        // Check if a mapping exists
        if (mappings.Contains(mapping1))
        {
            Console.WriteLine("Collection contains mapping1.");
        }

        // Remove a mapping
        mappings.Remove(mapping2);
        Console.WriteLine($"After removing mapping2, count is: {mappings.Count}");
    }
}
                
Requirements

Namespace: System.Net.Security

Assembly: System (in System.dll)

.NET Framework .NET Core .NET Standard
Supported in version 1.0 and later Supported in version 1.0 and later Supported in version 2.0 and later