BindingCollection 类

定义

表示绑定的集合。

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)
继承

示例

以下示例显示跟踪侦听器的每个绑定的计数。

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());
} 

以下示例列出了服务器上每个站点的每个绑定。

[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;
}

注解

可以在 IIS 管理器的“ 站点绑定 ”对话框中查看站点的绑定。 若要打开对话框,请右键单击“ 连接 ”窗格中的站点节点,然后单击“ 编辑绑定”。 “ 网站绑定 ”对话框显示 Binding 网站的 对象中的 BindingCollection 对象。

BindingCollection在通过调用 方法更新ApplicationHost.config文件之前,对对象的更改不会反映在 IIS 管理器中Microsoft.Web.Management.Server.ManagementUnit.Update

属性

AllowsAdd

获取一个值,该值指示元素名称是否 add 在当前集合架构中定义。

(继承自 ConfigurationElementCollectionBase<T>)
AllowsClear

获取一个值,该值指示是否 clear 在当前集合架构中定义了元素名称。

(继承自 ConfigurationElementCollectionBase<T>)
AllowsRemove

获取一个值,该值指示是否 remove 在当前集合架构中定义了元素名称。

(继承自 ConfigurationElementCollectionBase<T>)
Attributes

获取包含此元素的属性列表的配置属性集合。

(继承自 ConfigurationElement)
ChildElements

获取当前元素的所有子元素。

(继承自 ConfigurationElement)
Count

获取集合中的项数。

(继承自 ConfigurationElementCollectionBase<T>)
ElementTagName

表示绑定的集合。

(继承自 ConfigurationElement)
IsLocallyStored

获取一个值,该值指示配置元素是否存储在特定的配置文件中。

(继承自 ConfigurationElement)
Item[Int32]

获取指定索引处的配置元素。

(继承自 ConfigurationElementCollectionBase<T>)
Item[String]

获取或设置具有指定名称的属性。

(继承自 ConfigurationElement)
Methods

获取配置元素的方法集合。

(继承自 ConfigurationElement)
RawAttributes

表示绑定的集合。

(继承自 ConfigurationElement)
Schema

获取描述配置元素集合的架构。

(继承自 ConfigurationElementCollectionBase<T>)

方法

Add(Binding)

将安全绑定添加到集合的末尾。

Add(String, Byte[], String)

将安全绑定添加到绑定集合。

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

表示绑定的集合。

Add(String, String)

将具有指定协议和绑定信息的绑定添加到绑定集合。

Add(T)

将配置元素添加到当前集合的末尾。

(继承自 ConfigurationElementCollectionBase<T>)
AddAt(Int32, T)

将配置元素添加到当前集合中的指定索引处。

(继承自 ConfigurationElementCollectionBase<T>)
Clear()

清除当前集合中的所有配置元素。

(继承自 ConfigurationElementCollectionBase<T>)
CreateElement()

为当前集合创建新的子元素。

(继承自 ConfigurationElementCollectionBase<T>)
CreateElement(String)

使用指定的名称创建新的子元素。

(继承自 ConfigurationElementCollectionBase<T>)
CreateNewElement(String)

使用指定的元素名称创建新元素。

(继承自 ConfigurationElementCollectionBase<T>)
Delete()

表示绑定的集合。

(继承自 ConfigurationElement)
GetAttribute(String)

返回一个 ConfigurationAttribute 对象,该对象表示请求的属性。

(继承自 ConfigurationElement)
GetAttributeValue(String)

返回指定特性的值。

(继承自 ConfigurationElement)
GetChildElement(String)

返回当前配置元素下且具有指定名称的子元素。

(继承自 ConfigurationElement)
GetChildElement(String, Type)

返回一个子元素,该子元素位于当前配置元素下,具有指定的名称和类型。

(继承自 ConfigurationElement)
GetCollection()

返回当前配置元素的默认集合。

(继承自 ConfigurationElement)
GetCollection(String)

返回属于当前配置元素的所有配置元素。

(继承自 ConfigurationElement)
GetCollection(String, Type)

返回具有指定名称和类型的配置元素,并且位于当前配置元素下。

(继承自 ConfigurationElement)
GetCollection(Type)

返回具有指定类型且位于当前配置元素下的配置元素。

(继承自 ConfigurationElement)
GetEnumerator()

返回循环访问集合的枚举数。

(继承自 ConfigurationElementCollectionBase<T>)
GetMetadata(String)

从元素架构返回元数据值。

(继承自 ConfigurationElement)
IndexOf(T)

确定集合中元素的索引。

(继承自 ConfigurationElementCollectionBase<T>)
Remove(Binding)

从绑定集合中删除指定的绑定。

Remove(Binding, Boolean)

表示绑定的集合。

Remove(T)

从集合中删除元素的第一个匹配项。

(继承自 ConfigurationElementCollectionBase<T>)
RemoveAt(Int32)

删除指定索引处的绑定。

SetAttributeValue(String, Object)

设置所指定特性的值。

(继承自 ConfigurationElement)
SetMetadata(String, Object)

设置元素架构中的元数据值。

(继承自 ConfigurationElement)

显式接口实现

ICollection.CopyTo(Array, Int32)

从特定的数组索引开始,将集合的元素复制到数组中。

(继承自 ConfigurationElementCollectionBase<T>)
ICollection.Count

表示绑定的集合。

(继承自 ConfigurationElementCollectionBase<T>)
ICollection.IsSynchronized

表示绑定的集合。

(继承自 ConfigurationElementCollectionBase<T>)
ICollection.SyncRoot

表示绑定的集合。

(继承自 ConfigurationElementCollectionBase<T>)
IEnumerable.GetEnumerator()

返回一个循环访问集合的枚举器。

(继承自 ConfigurationElementCollectionBase<T>)

适用于