Adding a Default Binding <binding>
Overview
The <binding>
element of the <bindings>
element allows you to configure the information required for requests to communicate with a Web site.
You can configure binding information when you create a Web site, or you can edit the binding information after you create the site. Binding information includes the protocol that clients use to communicate with the site, the site's IP address, the port number, and a host header.
The <binding>
element contains two attributes to configure the binding information: bindingInformation and protocol. The bindingInformation attribute contains the IP address, the port number and, optionally, the host header for the site. The protocol attribute defines the protocol to use to communicate with the site.
Compatibility
Version | Notes |
---|---|
IIS 10.0 | The <binding> element was not modified in IIS 10.0. |
IIS 8.5 | The <binding> element was not modified in IIS 8.5. |
IIS 8.0 | The sslFlags attribute was added to specify the binding used for Secure Sockets Layer certificates. |
IIS 7.5 | The <binding> element was not modified in IIS 7.5. |
IIS 7.0 | The <binding> element of the <bindings> collection was introduced in IIS 7.0. |
IIS 6.0 | The <bindings> collection replaces sections of the ServerBindings property on the IIS 6.0 IIsWebServer metabase object. |
Setup
The <binding>
element is included in the default installation of IIS 7 and later.
How To
How to add default binding information to a server
Open Internet Information Services (IIS) Manager:
If you are using Windows Server 2012 or Windows Server 2012 R2:
- On the taskbar, click Server Manager, click Tools, and then click Internet Information Services (IIS) Manager.
If you are using Windows 8 or Windows 8.1:
- Hold down the Windows key, press the letter X, and then click Control Panel.
- Click Administrative Tools, and then double-click Internet Information Services (IIS) Manager.
If you are using Windows Server 2008 or Windows Server 2008 R2:
- On the taskbar, click Start, point to Administrative Tools, and then click Internet Information Services (IIS) Manager.
If you are using Windows Vista or Windows 7:
- On the taskbar, click Start, and then click Control Panel.
- Double-click Administrative Tools, and then double-click Internet Information Services (IIS) Manager.
In the Connections pane, select the server name.
In the Home pane, double-click Configuration Editor.
Move to system.applicationHost/sites in Section.
In the Site Bindings dialog box, click Add....
Expand siteDefaults.
Select bindings and then click the ellipsis to the right to open the Collection Editor.
Click Add, and enter values for bindingInformation, protocol, and sslFlags.
Close Collection Editor and in the Actions pane, click Apply.
Configuration
You can add default <binding>
elements within the <bindings>
element in the <siteDefaults>
section of the ApplicationHost.config file.
Attribute | Description |
---|---|
bindingInformation |
Required string attribute. Specifies information to communicate with a site. For example, a Web site binding includes the IP address (or unspecified IP addresses), the port number, and an optional host header used to communicate with the site. |
protocol |
Required string attribute. Specifies the protocol for communicating with a site. |
sslFlags |
Optional uint attribute. Specifies the type of binding used for Secure Sockets Layer (SSL) certificates.
With a Server Name Indicator (SNI), the host name is exchanged as part of the SSL handshake. SNI is enabled in the Add Site Binding dialog box when you add a binding with a type of HTTPS. This is especially useful for SSL connections that host multiple servers on a single network address. The default value is 0 . |
Child Elements
None.
Configuration Sample
The following configuration sample specifies the default bindings
options for IIS 7.
<system.applicationHost>
<sites>
<siteDefaults>
<bindings>
<binding protocol="http" bindingInformation="127.0.0.1:8080:" />
</bindings>
</siteDefaults>
</sites>
</system.applicationHost>
Sample Code
The following code samples configure the default bindings
options for IIS 7.
AppCmd.exe
appcmd.exe set config -section:system.applicationHost/sites /siteDefaults.bindings.[protocol='http',bindingInformation='*:8080:contoso.com'].bindingInformation:"127.0.0.1:8080:" /commit:apphost
Note
You must be sure to set the commit parameter to apphost
when you use AppCmd.exe to configure these settings. This commits the configuration settings to the appropriate location section in the ApplicationHost.config file.
C#
using System;
using System.Text;
using Microsoft.Web.Administration;
internal static class Sample
{
private static void Main()
{
using (ServerManager serverManager = new ServerManager())
{
Configuration config = serverManager.GetApplicationHostConfiguration();
ConfigurationSection sitesSection = config.GetSection("system.applicationHost/sites");
ConfigurationElement siteDefaultsElement = sitesSection.GetChildElement("siteDefaults");
ConfigurationElementCollection bindingsCollection = siteDefaultsElement.GetCollection("bindings");
ConfigurationElement bindingElement = bindingsCollection.CreateElement("binding");
bindingElement["protocol"] = @"http";
bindingElement["bindingInformation"] = @"127.0.0.1:8080:";
bindingsCollection.Add(bindingElement);
serverManager.CommitChanges();
}
}
}
VB.NET
Imports System
Imports System.Text
Imports Microsoft.Web.Administration
Module Sample
Sub Main()
Dim serverManager As ServerManager = New ServerManager
Dim config As Configuration = serverManager.GetApplicationHostConfiguration
Dim sitesSection As ConfigurationSection = config.GetSection("system.applicationHost/sites")
Dim siteDefaultsElement As ConfigurationElement = sitesSection.GetChildElement("siteDefaults")
Dim bindingsCollection As ConfigurationElementCollection = siteDefaultsElement.GetCollection("bindings")
Dim bindingElement As ConfigurationElement = bindingsCollection.CreateElement("binding")
bindingElement("protocol") = "http"
bindingElement("bindingInformation") = "127.0.0.1:8080:"
bindingsCollection.Add(bindingElement)
serverManager.CommitChanges()
End Sub
End Module
JavaScript
var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";
var sitesSection = adminManager.GetAdminSection("system.applicationHost/sites", "MACHINE/WEBROOT/APPHOST");
var siteDefaultsElement = sitesSection.ChildElements.Item("siteDefaults");
var bindingsCollection = siteDefaultsElement.ChildElements.Item("bindings").Collection;
var bindingElement = bindingsCollection.CreateNewElement("binding");
bindingElement.Properties.Item("protocol").Value = "http";
bindingElement.Properties.Item("bindingInformation").Value = "127.0.0.1:8080:";
bindingsCollection.AddElement(bindingElement);
adminManager.CommitChanges();
VBScript
Set adminManager = WScript.CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"
Set sitesSection = adminManager.GetAdminSection("system.applicationHost/sites", "MACHINE/WEBROOT/APPHOST")
Set siteDefaultsElement = sitesSection.ChildElements.Item("siteDefaults")
Set bindingsCollection = siteDefaultsElement.ChildElements.Item("bindings").Collection
Set bindingElement = bindingsCollection.CreateNewElement("binding")
bindingElement.Properties.Item("protocol").Value = "http"
bindingElement.Properties.Item("bindingInformation").Value = "127.0.0.1:8080:"
bindingsCollection.AddElement(bindingElement)
adminManager.CommitChanges()