BindingCollection.RemoveAt(Int32) Method
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.
Removes a binding at the specified index.
public:
void RemoveAt(int index);
public void RemoveAt (int index);
override this.RemoveAt : int -> unit
Public Sub RemoveAt (index As Integer)
Parameters
- index
- Int32
The index of the binding to be removed.
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 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
When a binding element is removed from the BindingCollection object and updated with the Update method, it is deleted in the ApplicationHost.config file.
After a binding has been deleted and the ApplicationHost.config file has been updated, the deleted binding will no longer appear in the Site Bindings dialog box.