BindingCollection Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Represents a collection of bindings.
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)
- Inheritance
Examples
The following example displays the count of each binding to the trace listener.
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());
}
The following example lists each bindings for each site on the server.
[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;
}
Remarks
You can view the bindings for a site in the Site Bindings dialog box in IIS Manager. To open the dialog box, right-click a site node in the Connections pane, and then click Edit Bindings. The Site Bindings dialog box displays the Binding objects in the BindingCollection object for the site.
Changes to the BindingCollection object are not reflected in IIS Manager until the ApplicationHost.config file is updated by a call to the Microsoft.Web.Management.Server.ManagementUnit.Update method.
Properties
AllowsAdd |
Gets a value indicating whether an |
AllowsClear |
Gets a value indicating whether a |
AllowsRemove |
Gets a value indicating whether a |
Attributes |
Gets a configuration attribute collection that contains the list of attributes for this element. (Inherited from ConfigurationElement) |
ChildElements |
Gets all the child elements of the current element. (Inherited from ConfigurationElement) |
Count |
Gets the number of items in the collection. (Inherited from ConfigurationElementCollectionBase<T>) |
ElementTagName | (Inherited from ConfigurationElement) |
IsLocallyStored |
Gets a value indicating whether the configuration element is stored in a particular configuration file. (Inherited from ConfigurationElement) |
Item[Int32] |
Gets a configuration element at the specified index. (Inherited from ConfigurationElementCollectionBase<T>) |
Item[String] |
Gets or sets an attribute with the specified name. (Inherited from ConfigurationElement) |
Methods |
Gets a collection of methods for the configuration element. (Inherited from ConfigurationElement) |
RawAttributes | (Inherited from ConfigurationElement) |
Schema |
Gets the schema that describes the configuration element collection. (Inherited from ConfigurationElementCollectionBase<T>) |
Methods
Add(Binding) |
Adds a secure binding to the end of the collection. |
Add(String, Byte[], String, SslFlags) | |
Add(String, Byte[], String) |
Adds a secure binding to the binding collection. |
Add(String, String) |
Adds a binding with the specified protocol and binding information to the binding collection. |
Add(T) |
Adds a configuration element to the end of the current collection. (Inherited from ConfigurationElementCollectionBase<T>) |
AddAt(Int32, T) |
Adds a configuration element to the current collection at the specified index. (Inherited from ConfigurationElementCollectionBase<T>) |
Clear() |
Clears all configuration elements from the current collection. (Inherited from ConfigurationElementCollectionBase<T>) |
CreateElement() |
Creates a new child element for the current collection. (Inherited from ConfigurationElementCollectionBase<T>) |
CreateElement(String) |
Creates a new child element by using the specified name. (Inherited from ConfigurationElementCollectionBase<T>) |
CreateNewElement(String) |
Creates a new element by using the specified element name. (Inherited from ConfigurationElementCollectionBase<T>) |
Delete() | (Inherited from ConfigurationElement) |
GetAttribute(String) |
Returns a ConfigurationAttribute object that represents the requested attribute. (Inherited from ConfigurationElement) |
GetAttributeValue(String) |
Returns the value of the specified attribute. (Inherited from ConfigurationElement) |
GetChildElement(String, Type) |
Returns a child element that is under the current configuration element and has the specified name and type. (Inherited from ConfigurationElement) |
GetChildElement(String) |
Returns a child element that is under the current configuration element and has the specified name. (Inherited from ConfigurationElement) |
GetCollection() |
Returns the default collection for the current configuration element. (Inherited from ConfigurationElement) |
GetCollection(String, Type) |
Returns the configuration element that has the specified name and type and is under the current configuration element. (Inherited from ConfigurationElement) |
GetCollection(String) |
Returns all configuration elements that belong to the current configuration element. (Inherited from ConfigurationElement) |
GetCollection(Type) |
Returns the configuration element that has the specified type and is under the current configuration element. (Inherited from ConfigurationElement) |
GetEnumerator() |
Returns an enumerator that iterates through a collection. (Inherited from ConfigurationElementCollectionBase<T>) |
GetMetadata(String) |
Returns metadata values from the element schema. (Inherited from ConfigurationElement) |
IndexOf(T) |
Determines the index of an element in the collection. (Inherited from ConfigurationElementCollectionBase<T>) |
Remove(Binding, Boolean) | |
Remove(Binding) |
Removes the specified binding from the binding collection. |
Remove(T) |
Removes the first occurrence of an element from the collection. (Inherited from ConfigurationElementCollectionBase<T>) |
RemoveAt(Int32) |
Removes a binding at the specified index. |
SetAttributeValue(String, Object) |
Sets the value of the specified attribute. (Inherited from ConfigurationElement) |
SetMetadata(String, Object) |
Sets metadata values from the element schema. (Inherited from ConfigurationElement) |
Explicit Interface Implementations
ICollection.CopyTo(Array, Int32) |
Copies the elements of the collection to an array, starting at a particular array index. (Inherited from ConfigurationElementCollectionBase<T>) |
ICollection.Count | (Inherited from ConfigurationElementCollectionBase<T>) |
ICollection.IsSynchronized | (Inherited from ConfigurationElementCollectionBase<T>) |
ICollection.SyncRoot | (Inherited from ConfigurationElementCollectionBase<T>) |
IEnumerable.GetEnumerator() |
Returns an enumerator that iterates through the collection. (Inherited from ConfigurationElementCollectionBase<T>) |