Add IIS bindings from applicationhost.config

I have a prelive site with about 70 domain names, is there a way to add this in octopus deploy using an applicationhost.config file instead of having to add one by one the 70 domains?

Hi Roberto,

Thanks for getting in touch. Unfortunately there isn’t a better way to do what you are asking at the moment.

Your best bet will be to create a powershell script that reads your applicationhost.config and adds your bindings as a post-deploy step.

Sorry its not better news

Dalmiro

Thanks for your reply, is there anyway to tell octopack not to overwrite the IIS site? Just use the existing configuration if the site already exists.

De: Dalmiro Grañas [mailto:tender2+dafdbdbc28@tenderapp.com]
Enviado el: Monday, May 04, 2015 10:37
Para: Roberto Yudice
Asunto: Re: Add IIS bindings from applicationhost.config [Questions #4739]

Hi Roberto,

I’m sad to say its not possible at the time. You can either do nothing to the website, or do everything (create/update). We do have a github issue to improve this process for scenarios liek yours

I’ll be writing a script to export bindings from an existing site to a file and then import them back sometime this week. I’ll let you know once i have something

Thanks

Dalmiro

I recently had to add 450+ host-headers to a site deployed using Octopus. The script I ended up with is this:

#-------------------------------------
# Bind hostheader for bb_redirects 
#-------------------------------------

Import-Module WebAdministration

# Set a name of the site we want to recycle the pool for:
$siteName = $OctopusParameters['WebSiteName']

Write-Output "Setting up array"

$BindingArray = @(
"*:80:www.domain1.com",
"*:80:www.domain2.com",
"*:80:www.domain3.com",
"*:80:www.domain4.com"
)

$site = "IIS:\Sites\$siteName"

$siteItem = (Get-Item $site)

# Stop website
Write-Output "Stopping website $($site)"
Stop-WebItem $site

Write-Output "Current number of bindings = $($siteItem.bindings.Collection.Count)" 

#Clear bindings for site
Clear-ItemProperty $site -Name bindings
$siteItem = (Get-Item $site)

Write-Output "Cleared: Current count = $($siteItem.bindings.Collection.Count)"

#Add bindings
Write-Output "$($BindingArray.Count) bindings will be added"
$headers = @()
Foreach ($binding in $BindingArray) {
   $object= [pscustomobject]@{protocol="http";bindingInformation="$binding";sslFlags=0;}
   $headers += $object
}    
New-ItemProperty  $site -Name bindings -Value $headers

$siteItem = (Get-Item $site)
Write-Output "$i bindings added. Current count = $($siteItem.bindings.Collection.Count)" 

Write-Output "Starting website $($site)"
Start-WebItem $site

This is overly complex but works. We tuned it and adding all bindings to an array of PSCustomObjects made it very quick to add all these headers.