BindingCollection.Add Method

Definition

Adds an HTTP or HTTPS binding to the binding collection.

Overloads

Add(Binding)

Adds a secure binding to the end of the collection.

Add(String, String)

Adds a binding with the specified protocol and binding information to the binding collection.

Add(String, Byte[], String)

Adds a secure binding to the binding collection.

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

Add(Binding)

Adds a secure binding to the end of the collection.

public:
 Microsoft::Web::Administration::Binding ^ Add(Microsoft::Web::Administration::Binding ^ binding);
public Microsoft.Web.Administration.Binding Add (Microsoft.Web.Administration.Binding binding);
override this.Add : Microsoft.Web.Administration.Binding -> Microsoft.Web.Administration.Binding

Parameters

binding
Binding

The Binding object to add to the collection.

Returns

The binding that was added to the collection.

Exceptions

The binding parameter is null.

Remarks

When a binding element is added to the BindingCollection object and updated with the Update method, it is stored in the ApplicationHost.config file.

After a binding has been added and the ApplicationHost.config file has been updated, IIS Manager will show the new binding in the Site Bindings dialog box.

Applies to

Add(String, String)

Adds a binding with the specified protocol and binding information to the binding collection.

public:
 Microsoft::Web::Administration::Binding ^ Add(System::String ^ bindingInformation, System::String ^ bindingProtocol);
public Microsoft.Web.Administration.Binding Add (string bindingInformation, string bindingProtocol);
override this.Add : string * string -> Microsoft.Web.Administration.Binding
Public Function Add (bindingInformation As String, bindingProtocol As String) As Binding

Parameters

bindingInformation
String

The binding information for a Web site.

bindingProtocol
String

The protocol that the site binding uses. The bindingProtocol parameter must be "http" or "https".

Returns

The binding that was added to the collection.

Remarks

The bindingInformation parameter has three colon-delimited fields. The first field is a specific IP address or an asterisk (an asterisk specifies all unassigned IP addresses). The second field is the port number; the default is 80. The third field is an optional host header.

An attempt to add a binding that already exists will raise an error.

When a binding element is added to the BindingCollection object and updated with the Update method, it is stored in the ApplicationHost.config file.

After a binding has been added and the ApplicationHost.config file has been updated, IIS Manager will show the new binding in the Site Bindings dialog box.

Applies to

Add(String, Byte[], String)

Adds a secure binding to the binding collection.

public:
 Microsoft::Web::Administration::Binding ^ Add(System::String ^ bindingInformation, cli::array <System::Byte> ^ certificateHash, System::String ^ certificateStoreName);
public Microsoft.Web.Administration.Binding Add (string bindingInformation, byte[] certificateHash, string certificateStoreName);
override this.Add : string * byte[] * string -> Microsoft.Web.Administration.Binding
Public Function Add (bindingInformation As String, certificateHash As Byte(), certificateStoreName As String) As Binding

Parameters

bindingInformation
String

The binding information for a Web site.

certificateHash
Byte[]

The certificate hash for the Secure Sockets Layer (SSL) binding. The certificate hash is the unique identifier for the certificate.

certificateStoreName
String

The name of the certificate store for the SSL binding.

Returns

The binding that was added to the collection.

Examples

The following example retrieves a valid certificate hash and certificate store name from an existing site binding that uses the "https" protocol. The example then adds a binding to the binding collection with the retrieved certificate hash and certificate store, specifying binding information of "*:448:TestingSite". Finally, the example updates the ApplicationHost.config file, and the newly defined binding appears in the Site Bindings dialog box. If the binding already exists, the binding is deleted, allowing the user to toggle between adding and deleting the binding. This example is part of a larger example provided for the [Add Method (String, Byte<xref:Microsoft.Web.Administration.BindingCollection> class.

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

Remarks

This method adds a [Add Method (String, Byte<xref:Microsoft.Web.Administration.Binding> object with the "https" protocol to the [Add Method (String, Byte<xref:Microsoft.Web.Administration.BindingCollection> object. The bindingInformation parameter has three colon-delimited fields. The first field is a specific IP address or an asterisk (an asterisk specifies all unassigned IP addresses). The second field is the port number; the default is 80. The third field is an optional host header.

An attempt to add a binding that already exists will raise an error.

When a binding element is added to the [Add Method (String, Byte<xref:Microsoft.Web.Administration.BindingCollection> object and updated with the [Add Method (String, Byte<xref:Microsoft.Web.Management.Server.ManagementUnit.Update%2A> method, it is stored in the ApplicationHost.config file.

After a binding has been added and the ApplicationHost.config file has been updated, IIS Manager will show the new binding in the Site Bindings dialog box.

Applies to

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

public:
 Microsoft::Web::Administration::Binding ^ Add(System::String ^ bindingInformation, cli::array <System::Byte> ^ certificateHash, System::String ^ certificateStoreName, Microsoft::Web::Administration::SslFlags sslFlags);
public Microsoft.Web.Administration.Binding Add (string bindingInformation, byte[] certificateHash, string certificateStoreName, Microsoft.Web.Administration.SslFlags sslFlags);
override this.Add : string * byte[] * string * Microsoft.Web.Administration.SslFlags -> Microsoft.Web.Administration.Binding

Parameters

bindingInformation
String
certificateHash
Byte[]
certificateStoreName
String
sslFlags
SslFlags

Returns

Applies to