2

I am trying to add a list of site bindings to the applicationHost.config file as opposed to manually adding each one through IIS 7.5.

<site name="new_site" id="6">
    <application path="/" applicationPool="new_site">
        <virtualDirectory path="/" physicalPath="D:\HTTP\wwwroot\newsite" />
    </application>
    <bindings>
        <binding protocol="http" bindingInformation="*:80:example.com" />
        <binding protocol="http" bindingInformation="*:80:www.example.com" />
        <binding protocol="http" bindingInformation="*:80:example2.com" />
        <binding protocol="http" bindingInformation="*:80:www.example2.com" />
    </bindings>
</site>

The reason for doing this is i have 2000 bindings to add, which would be a lot easier to do if i could edit the config file directly.

When editing the config file however the bindings do not work or show up in IIS.

Is this actually possible or am i missing something?

Leo
  • 224
  • 1
  • 3
  • 12

3 Answers3

0

You should use Microsoft.Web.Administration assembly and create sites trough that API. Here is the example of creating a site

http://learn.iis.net/page.aspx/226/microsoftwebadministration/

Antonio Bakula
  • 20,445
  • 6
  • 75
  • 102
0

You could script this in PowerShell:

[Reflection.Assembly]::Load(
"Microsoft.Web.Administration, Version=7.0.0.0, 
Culture=Neutral, PublicKeyToken=31bf3856ad364e35") > $null

$siteId = 6
$serverManager = New-Object Microsoft.Web.Administration.ServerManager
$site = $serverManager.Sites | where { $_.Id -eq $siteID }

# Read your list of hostnames

$reader = [System.IO.File]::OpenText("c:\\hostnames.txt")
for(;;) 
{
    $domainName = $reader.ReadLine()
    if($domainName -eq $null) { break }
    $binding1 = "*:80:www." + $domainName
    $binding2 = "*:80:" + $domainName
    $site.Bindings.Add($binding1, "http")
    $site.Bindings.Add($binding2, "http")
}
$serverManager.CommitChanges()

The file c:\\hostnames.txt would contain a list of all your domain names, for example:

domanname1.com
domanname2.com
domanname3.com

If you need to bind to a specific IP address then replace * with the IP address.

Kev
  • 118,037
  • 53
  • 300
  • 385
0

Are you using a 32-bit editor on a 64 bit machine? If so, Windows is saving your edits to C:\Windows\SysWOW64\inetsrv\Config\applicationHost.config.

See https://serverfault.com/questions/315904/cannot-open-iis-7-applicationhost-config-in-64-bit-windows-with-32-bit-text-edit

Community
  • 1
  • 1