4

How do I programmatically add an additional domain name to an Azure Web Site?

Hopefully there .NET API for this that I missed, perhaps in the Azure SDK or a NuGet package. Or perhaps there is a REST interface.

Edward Brey
  • 40,302
  • 20
  • 199
  • 253

2 Answers2

3

The Windows Azure Web Sites Management REST API should provide the functionality you are looking for.

The property Site.HostNames property of Windows Azure Web Site can be used to provide additional domain names. The properties can be provided during creation of a web site or when updating.

Please also take note of the general info on Configuring a custom domain name for a Windows Azure web site. You would also have to programmatically add the verification entry to your DNS.

I am not sure if there are any wrapper SDKs/libs/powershell commandlets for the web sites management API.

makhdumi
  • 1,308
  • 11
  • 35
Simon Opelt
  • 6,136
  • 2
  • 35
  • 66
  • The broken dokumentation URLs are a very unfortunate situation. What exactly are you trying to do @AnnArbor87? You could have a look at the xplat cli tools (e.g. https://github.com/Azure/azure-xplat-cli/blob/dev/lib/commands/asm/site.domain._js ) which seem to support such operations via Azure Resource Manager. That probably implies that https://msdn.microsoft.com/en-us/library/azure/dn790568.aspx might provide the required (now generic) operations. – Simon Opelt Sep 25 '15 at 19:59
  • I posted my question here http://stackoverflow.com/questions/32789231/azure-update-resource-property-with-rest-api – AAlferez Sep 25 '15 at 20:27
1

This can be done using either the (Azure Management) Services API, the Resources API, or the Azure RM PowerShell cmdlets.

I find using the Services API easiest, because of bugs with logging in with Microsoft accounts with PowerShell, and the absurd requirement of needing to create an Azure RM app as a GlobalAdmin in order to use the Resources API.

PowerShell

Login-AzureRmAccount  # Non-automatable because pops up OAuth window. -Credentials parameter is broken.
Set-AzureRmWebapp -Name 'SiteName' -ResourceGroupName 'ResourceGroup' -HostNames @('SiteName.azurewebsites.net', ...)

Services REST API

Requires Client Certificate in request. Generate/download new certificates here

PUT https://management.core.windows.net:8443/{subscriptionId}/services/webspaces/{webspace}/sites/{siteName}
Accept: application/json
Content-Type: application/json
x-ms-version: 2015-04-01

{
    HostNames: ['siteName.azurewebsites.net',...]
}

Resources REST API

Requires Global Administrator account (Co-Admin does not work). Follow instructions here for setup

PUT https://management.azure.com/subscriptions/<subscriptionId>/resourcegroups/resourceGroup>/providers/Microsoft.Web/sites/<siteName>?api-version=2015-04-01
Accept: application/json
Content-Type: application/json

{
    HostNames: ['siteName.azurewebsites.net',...]
}
makhdumi
  • 1,308
  • 11
  • 35
  • For the powershell command at least you should only include the custom domains and not the azurewebsites.net value, see http://stackoverflow.com/questions/27830895/setting-host-names-for-azure-websites-via-azure-powershell, – Paul Hatcher Jan 11 '17 at 12:38