4

Is there a way to create a web site with Release Management v12 that will include a host header option?

My goal is to be able to host multiple sites on a single server, all binding to port 80 with different host headers. i.e. http://project1.development.local/, http://project2.development.local/

I'm able to create a web site with a host header from the AppCmd.exe, yet this requires an administration rights. Thought about using powershell, yet a UAC prompt will be triggered.

For right now, I'm having to manually create the server's web site to include the host header and I'd like to have a totally automated release process.

TIA!

Tetsujin no Oni
  • 7,300
  • 2
  • 29
  • 46
Werewolf
  • 472
  • 3
  • 11

1 Answers1

4

There's nothing in-the-box for it, but as luck would have it, I've hacked something together to handle site bindings:

param( 
$SiteName=$(throw "Site Name must be entered"), 
$HostHeader,
$IpAddress,
$Port,
$RemoveDefault=$(throw "You must specify true or false") 
) 


Import-Module WebAdministration 

try { 
  $bindingExists = (Get-WebBinding "$SiteName" -Port "$Port" -Protocol "http" -HostHeader "$HostHeader" -IPAddress "$IpAddress") 

  if (!$bindingExists) { 
      Write-host "Creating binding for $SiteName : Host header $HostHeader and IP Address $IpAddress" 
      New-WebBinding "$SiteName" -Port $Port -Protocol "http" -HostHeader "$HostHeader" -IPAddress "$IpAddress" 

  } 
  else { 
      Write-host "Site $SiteName already has binding for host header $HostHeader and IP Address $IpAddress" 
  } 

  if ($RemoveDefault -eq "true") { 
      $defaultBinding = Get-WebBinding "$SiteName" | where {$_.bindingInformation -eq "*:80:" } 
      if ($defaultBinding -ne $null) { 
          Write-Host "Default binding exists... removing." 
          $defaultBinding | Remove-WebBinding 
      } 
      else { 
          Write-Host "Default binding does not exist" 
      } 
  } 
} 
catch { 
  Write-host $_ 
  exit 1 
} 
exit 0 

You can create a custom tool in RM to leverage this script, just pass it the parameters specified in the param block.

You should never have to use AppCmd.exe... If the built-in tools don't meet your needs, the WebAdministration PowerShell module should be able to do everything else.

Daniel Mann
  • 57,011
  • 13
  • 100
  • 120