Share via


BindingCollection Klasse

Definition

Stellt eine Auflistung von Bindungen dar.

public ref class BindingCollection sealed : Microsoft::Web::Administration::ConfigurationElementCollectionBase<Microsoft::Web::Administration::Binding ^>
public sealed class BindingCollection : Microsoft.Web.Administration.ConfigurationElementCollectionBase<Microsoft.Web.Administration.Binding>
type BindingCollection = class
    inherit ConfigurationElementCollectionBase<Binding>
Public NotInheritable Class BindingCollection
Inherits ConfigurationElementCollectionBase(Of Binding)
Vererbung

Beispiele

Im folgenden Beispiel wird die Anzahl jeder Bindung an den Ablaufverfolgungslistener angezeigt.

void ShowBE(Object propertyToConvert) {

    BindingCollection bindingColl = propertyToConvert as BindingCollection;
    int httpsCnt=0;
    int httpCnt=0;
    int unknownCnt=0;

    foreach (Microsoft.Web.Administration.Binding  bindElem in bindingColl) {
        if (bindElem.Protocol.Equals(
            "https", StringComparison.InvariantCultureIgnoreCase) ) {
            httpsCnt++;
        } else if (bindElem.Protocol.Equals(
            "http", StringComparison.InvariantCultureIgnoreCase) ){
           httpCnt++;
        }
        else 
            unknownCnt++;
    }
    Trace.WriteLine("HTTPS Cnt = " + httpsCnt.ToString());
    Trace.WriteLine("HTTP Cnt = " + httpCnt.ToString());
    Trace.WriteLine("Unknown Cnt = " + unknownCnt.ToString());
} 

Im folgenden Beispiel werden alle Bindungen für jeden Standort auf dem Server aufgelistet.

[ModuleServiceMethod(PassThrough = true)]
public ArrayList GetSiteCollection()
{
    // Use an ArrayList to transfer objects to the client.
    ArrayList arrayOfSitePropertyBags = new ArrayList();

    SiteCollection siteCollection = 
        base.ManagementUnit.ServerManager.Sites;
    Site siteToModify = null;
    string newbindinginformation = String.Empty;
    byte[] newcertificateHash = null;
    string newcertificateStoreName = String.Empty;
    Int32 bindingIndex = -1;
    // Find a binding with an https protocol, if one exists.
    // Capture the site, certificate hash, and the certificate store name.
    foreach (Site site in siteCollection)
    {
        PropertyBag siteBag = new PropertyBag();

        siteBag[TestDemoGlobals.SiteName] = site.Name;
        siteBag[TestDemoGlobals.SiteId] = site.Id;

        ArrayList siteBindingsArray = new ArrayList();
        foreach (Microsoft.Web.Administration.Binding binding in site.Bindings)
        {
            PropertyBag bindingBag = new PropertyBag();

            bindingBag[TestDemoGlobals.BindingInformation] = binding.BindingInformation;
            if (binding.Protocol == "https")
            {
                // Capture certificate information for binding to be created later
                siteToModify = site;
                newcertificateHash = binding.CertificateHash;
                newcertificateStoreName = binding.CertificateStoreName;

                // Add certificate data to binding property bag
                bindingBag[TestDemoGlobals.BindingCertificateHashType] = 
                    binding.CertificateHash.ToString();
                string hashString = String.Empty;
                foreach (System.Byte certhashbyte in binding.CertificateHash)
                {
                    hashString += certhashbyte.ToString() + " ";
                }
                bindingBag[TestDemoGlobals.BindingCertificateHash] = hashString;
                bindingBag[TestDemoGlobals.BindingCertificateHashStoreName] = binding.CertificateStoreName;
            }
            bindingBag[TestDemoGlobals.BindingProtocol] = binding.Protocol;
            bindingBag[TestDemoGlobals.BindingEndPoint] = binding.EndPoint;
            bindingBag[TestDemoGlobals.BindingHost] = binding.Host;
            bindingBag[TestDemoGlobals.BindingIsIPPortHostBinding] = binding.IsIPPortHostBinding;
            bindingBag[TestDemoGlobals.BindingToString] = binding.ToString();
            bindingBag[TestDemoGlobals.BindingUseDsMapper] = binding.UseDsMapper;

            siteBindingsArray.Add(bindingBag);
        }

        siteBag[TestDemoGlobals.BindingsArrayList] = siteBindingsArray;

        arrayOfSitePropertyBags.Add(siteBag);
    }
    // Adding a duplicate binding throws an error.
    if (siteToModify != null)
    {
        newbindinginformation = "*:448:TestingSite";
        try
        {
            // Add this binding. It does not already exist. 
            siteToModify.Bindings.Add(newbindinginformation, newcertificateHash, newcertificateStoreName);
        }
        catch
        {
            // Remove this binding. It already exists.
            foreach (Microsoft.Web.Administration.Binding binding in siteToModify.Bindings)
            {
                if (binding.BindingInformation == newbindinginformation)
                {
                    bindingIndex = siteToModify.Bindings.IndexOf(binding);
                }
            }
            if (bindingIndex != -1)
            {
                siteToModify.Bindings.RemoveAt(bindingIndex);
            }
        }
        // Update information and save in Administration.config file.
        ManagementUnit.Update();
    }
    return arrayOfSitePropertyBags;
}

Hinweise

Sie können die Bindungen für eine Website im Dialogfeld Websitebindungen im IIS-Manager anzeigen. Klicken Sie zum Öffnen des Dialogfelds im Bereich Verbindungen mit der rechten Maustaste auf einen Standortknoten, und klicken Sie dann auf Bindungen bearbeiten. Im Dialogfeld Websitebindungen werden die Binding Objekte im BindingCollection -Objekt für die Website angezeigt.

Änderungen am BindingCollection -Objekt werden im IIS-Manager erst übernommen, wenn die ApplicationHost.config-Datei durch einen Aufruf der Microsoft.Web.Management.Server.ManagementUnit.Update -Methode aktualisiert wird.

Eigenschaften

AllowsAdd

Ruft einen Wert ab, der angibt, ob ein add Elementname im aktuellen Auflistungsschema definiert ist.

(Geerbt von ConfigurationElementCollectionBase<T>)
AllowsClear

Ruft einen Wert ab, der angibt, ob ein clear Elementname im aktuellen Auflistungsschema definiert ist.

(Geerbt von ConfigurationElementCollectionBase<T>)
AllowsRemove

Ruft einen Wert ab, der angibt, ob ein remove Elementname im aktuellen Auflistungsschema definiert ist.

(Geerbt von ConfigurationElementCollectionBase<T>)
Attributes

Ruft eine Konfigurationsattributeauflistung ab, die die Liste der Attribute für dieses Element enthält.

(Geerbt von ConfigurationElement)
ChildElements

Ruft alle untergeordneten Elemente des aktuellen Elements ab.

(Geerbt von ConfigurationElement)
Count

Ruft die Anzahl der Elemente in der Auflistung ab.

(Geerbt von ConfigurationElementCollectionBase<T>)
ElementTagName

Stellt eine Auflistung von Bindungen dar.

(Geerbt von ConfigurationElement)
IsLocallyStored

Ruft einen Wert ab, der angibt, ob das Konfigurationselement in einer bestimmten Konfigurationsdatei gespeichert ist.

(Geerbt von ConfigurationElement)
Item[Int32]

Ruft ein Konfigurationselement am angegebenen Index ab.

(Geerbt von ConfigurationElementCollectionBase<T>)
Item[String]

Ruft ein Attribut mit dem angegebenen Namen ab oder legt es fest.

(Geerbt von ConfigurationElement)
Methods

Ruft eine Auflistung von Methoden für das Konfigurationselement ab.

(Geerbt von ConfigurationElement)
RawAttributes

Stellt eine Auflistung von Bindungen dar.

(Geerbt von ConfigurationElement)
Schema

Ruft das Schema ab, das die Konfigurationselementauflistung beschreibt.

(Geerbt von ConfigurationElementCollectionBase<T>)

Methoden

Add(Binding)

Fügt am Ende der Auflistung eine sichere Bindung hinzu.

Add(String, Byte[], String)

Fügt der Bindungsauflistung eine sichere Bindung hinzu.

Add(String, Byte[], String, SslFlags)

Stellt eine Auflistung von Bindungen dar.

Add(String, String)

Fügt der Bindungsauflistung eine Bindung mit dem angegebenen Protokoll und Bindungsinformationen hinzu.

Add(T)

Fügt am Ende der aktuellen Auflistung ein Konfigurationselement hinzu.

(Geerbt von ConfigurationElementCollectionBase<T>)
AddAt(Int32, T)

Fügt der aktuellen Auflistung am angegebenen Index ein Konfigurationselement hinzu.

(Geerbt von ConfigurationElementCollectionBase<T>)
Clear()

Löscht alle Konfigurationselemente aus der aktuellen Auflistung.

(Geerbt von ConfigurationElementCollectionBase<T>)
CreateElement()

Erstellt ein neues untergeordnetes Element für die aktuelle Auflistung.

(Geerbt von ConfigurationElementCollectionBase<T>)
CreateElement(String)

Erstellt ein neues untergeordnetes Element unter Verwendung des angegebenen Namens.

(Geerbt von ConfigurationElementCollectionBase<T>)
CreateNewElement(String)

Erstellt unter Verwendung des angegebenen Elementnamens ein neues Element.

(Geerbt von ConfigurationElementCollectionBase<T>)
Delete()

Stellt eine Auflistung von Bindungen dar.

(Geerbt von ConfigurationElement)
GetAttribute(String)

Gibt ein ConfigurationAttribute -Objekt zurück, das das angeforderte Attribut darstellt.

(Geerbt von ConfigurationElement)
GetAttributeValue(String)

Gibt den Wert des angegebenen Attributs zurück.

(Geerbt von ConfigurationElement)
GetChildElement(String)

Gibt ein untergeordnetes Element zurück, das sich unter dem aktuellen Konfigurationselement befindet und den angegebenen Namen hat.

(Geerbt von ConfigurationElement)
GetChildElement(String, Type)

Gibt ein untergeordnetes Element zurück, das sich unter dem aktuellen Konfigurationselement befindet und den angegebenen Namen und Typ aufweist.

(Geerbt von ConfigurationElement)
GetCollection()

Gibt die Standardauflistung für das aktuelle Konfigurationselement zurück.

(Geerbt von ConfigurationElement)
GetCollection(String)

Gibt alle Konfigurationselemente zurück, die zum aktuellen Konfigurationselement gehören.

(Geerbt von ConfigurationElement)
GetCollection(String, Type)

Gibt das Konfigurationselement zurück, das über den angegebenen Namen und Typ verfügt und sich unter dem aktuellen Konfigurationselement befindet.

(Geerbt von ConfigurationElement)
GetCollection(Type)

Gibt das Konfigurationselement zurück, das über den angegebenen Typ verfügt und sich unter dem aktuellen Konfigurationselement befindet.

(Geerbt von ConfigurationElement)
GetEnumerator()

Gibt einen Enumerator zurück, der eine Auflistung durchläuft.

(Geerbt von ConfigurationElementCollectionBase<T>)
GetMetadata(String)

Gibt Metadatenwerte aus dem Elementschema zurück.

(Geerbt von ConfigurationElement)
IndexOf(T)

Bestimmt den Index eines Elements in der Auflistung.

(Geerbt von ConfigurationElementCollectionBase<T>)
Remove(Binding)

Entfernt die angegebene Bindung aus der Bindungsauflistung.

Remove(Binding, Boolean)

Stellt eine Auflistung von Bindungen dar.

Remove(T)

Entfernt das erste Vorkommen eines Elements aus der Auflistung.

(Geerbt von ConfigurationElementCollectionBase<T>)
RemoveAt(Int32)

Entfernt eine Bindung am angegebenen Index.

SetAttributeValue(String, Object)

Legt den Wert des angegebenen Attributs fest.

(Geerbt von ConfigurationElement)
SetMetadata(String, Object)

Legt Metadatenwerte aus dem Elementschema fest.

(Geerbt von ConfigurationElement)

Explizite Schnittstellenimplementierungen

ICollection.CopyTo(Array, Int32)

Kopiert die Elemente der Auflistung in ein Array, wobei an einem bestimmten Arrayindex begonnen wird.

(Geerbt von ConfigurationElementCollectionBase<T>)
ICollection.Count

Stellt eine Auflistung von Bindungen dar.

(Geerbt von ConfigurationElementCollectionBase<T>)
ICollection.IsSynchronized

Stellt eine Auflistung von Bindungen dar.

(Geerbt von ConfigurationElementCollectionBase<T>)
ICollection.SyncRoot

Stellt eine Auflistung von Bindungen dar.

(Geerbt von ConfigurationElementCollectionBase<T>)
IEnumerable.GetEnumerator()

Gibt einen Enumerator zurück, der die Auflistung durchläuft.

(Geerbt von ConfigurationElementCollectionBase<T>)

Gilt für: