【发布时间】:2013-09-14 20:45:18
【问题描述】:
如何以编程方式将其他域名添加到 Azure 网站?
希望有我错过的 .NET API,可能在 Azure SDK 或 NuGet 包中。或者也许有一个 REST 接口。
【问题讨论】:
标签: .net sdk azure-web-app-service
如何以编程方式将其他域名添加到 Azure 网站?
希望有我错过的 .NET API,可能在 Azure SDK 或 NuGet 包中。或者也许有一个 REST 接口。
【问题讨论】:
标签: .net sdk azure-web-app-service
Windows Azure 网站管理 REST API 应该提供您正在寻找的功能。
Windows Azure 网站的Site.HostNames 属性可用于提供额外的域名。这些属性可以在网站创建期间或更新时提供。
还请注意Configuring a custom domain name for a Windows Azure web site 上的一般信息。您还必须以编程方式将验证条目添加到您的 DNS。
我不确定网站管理 API 是否有任何包装 SDK/libs/powershell 命令行开关。
【讨论】:
这可以使用(Azure 管理)服务 API、资源 API 或 Azure RM PowerShell cmdlet 来完成。
我发现使用服务 API 最简单,因为使用 PowerShell 使用 Microsoft 帐户登录时会出现错误,并且需要以 GlobalAdmin 身份创建 Azure RM 应用程序才能使用资源 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', ...)
服务 REST API
请求中需要客户端证书。生成/下载新证书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',...]
}
资源 REST API
需要全局管理员帐户(Co-Admin 不起作用)。按照说明here 进行设置
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',...]
}
【讨论】: