Pro Tip: Bulk Update IIS Bindings

Have you ever worked on a multi-site Sitecore instance where you had to laboriously hand-enter 100 new bindings into IIS on 10 different servers? Well, I have and it's not fun - it can take all day and I'd rather be coding.

So I have a time-saving tip for you. The trick is to bypass the UI in IIS Manager and directly edit the Application Host configuration file. From IIS version 7.0 on, the IIS settings are exposed in an xml-formatted config file that you can edit to your heart's content.

Say, for example, you needed to add a whole slew of new bindings into IIS:

    www.contoso.com:80
    www.contoso.ar:80
    www.contoso.it:80
    www.contoso.com:443
    www.contoso.ar:443
    www.contoso.it:443
...and dozens more.

Here's how I would do it, the time-saving way.

1. First, I would enter a couple of the bindings the usual way through the IIS Manager UI, just so I can get a model for the entries.

2. Now stop all your IIS sites, and close the IIS Manager.

3. Open the Application Host config file, which on Windows Server 2012 lives here: C:\Windows\System32\inetsrv\Config\applicationHost.config.

4. Find the <sites> section, and then find the section for your <site>. It will look something like this:

<site name="Contoso" id="3" serverAutoStart="false">
  <application path="/" applicationPool="Contoso">
    <virtualDirectory path="/" physicalPath="C:\inetpub" />
  </application>
  <bindings>
    <binding protocol="http" bindingInformation="*:80:www.contoso.com" />
    <binding protocol="https" bindingInformation="*:443:www.contoso.com" sslFlags="0" />
  </bindings>
</site>

5. Take a look at the <bindings> section, and you'll see the two new binding entries you made through the UI.

6. Using those as a model, add as many new binding entries as you need. For example:

<bindings>
  <binding protocol="http" bindingInformation="*:80:www.contoso.com" />
  <binding protocol="https" bindingInformation="*:443:www.contoso.com" sslFlags="0" />
  <binding protocol="http" bindingInformation="*:80:www.contoso.ar" />
  <binding protocol="https" bindingInformation="*:443:www.contoso.ar" sslFlags="0" />
  <binding protocol="http" bindingInformation="*:80:www.contoso.it" />
  <binding protocol="https" bindingInformation="*:443:www.contoso.it" sslFlags="0" />
  <binding protocol="http" bindingInformation="*:80:www.contoso.eu" />
  <binding protocol="https" bindingInformation="*:443:www.contoso.eu" sslFlags="0" />
  <binding protocol="http" bindingInformation="*:80:www.contoso.gb" />
  <binding protocol="https" bindingInformation="*:443:www.contoso.gb" sslFlags="0" />
  <binding protocol="http" bindingInformation="*:80:www.contoso.fi" />
  <binding protocol="https" bindingInformation="*:443:www.contoso.fi" sslFlags="0" />
  <binding protocol="http" bindingInformation="*:80:www.contoso.hk" />
  <binding protocol="https" bindingInformation="*:443:www.contoso.hk" sslFlags="0" />
  <binding protocol="http" bindingInformation="*:80:www.contoso.in" />
  <binding protocol="https" bindingInformation="*:443:www.contoso.in" sslFlags="0" />
  <binding protocol="http" bindingInformation="*:80:www.contoso.id" />
  <binding protocol="https" bindingInformation="*:443:www.contoso.id" sslFlags="0" />
  <binding protocol="http" bindingInformation="*:80:www.contoso.pr" />
  <binding protocol="https" bindingInformation="*:443:www.contoso.pr" sslFlags="0" />
  <binding protocol="http" bindingInformation="*:80:www.contoso.pk" />
  <binding protocol="https" bindingInformation="*:443:www.contoso.pk" sslFlags="0" />
  <binding protocol="http" bindingInformation="*:80:www.contoso.qa" />
  <binding protocol="https" bindingInformation="*:443:www.contoso.qa" sslFlags="0" />
</bindings>

7. Save and close the file.

8. Open a command prompt as an administrator, and run IISRESET.

All done! Your new binding are ready to go.

Note: Some folks have reported that you need to reboot the computer after doing this kind of edit, but I've never had to.

Please share your thoughts with me on this blog, and let me know if you have new-and-improved methods to accomplish this.

~David

 

 

Add comment

Loading