2013-09-11 56 views
4

向Azure網站添加域如何以編程方式向Azure網站添加其他域名?通過代碼

希望有.NET API爲此我錯過了,也許在Azure SDK或NuGet包。或者也許有一個REST接口。

回答

3

Windows Azure網站管理REST API應提供您正在查找的功能。

屬性Site.HostNames Windows Azure網站的屬性可用於提供其他域名。這些屬性可以在創建網站或更新時提供。

還請注意關於Configuring a custom domain name for a Windows Azure web site的一般信息。您還必須以編程方式將驗證條目添加到您的DNS。

我不確定是否有任何用於網站管理API的包裝SDK/libs/powershell命令行開關。

+0

這是怎麼回事,REST API信息在哪裏? – AAlferez

+0

破碎的dokumentation網址是一個非常不幸的情況。你究竟在做什麼@ AnnArbor87?你可以看看似乎支持這些操作的xplat cli工具(例如https://github.com/Azure/azure-xplat-cli/blob/dev/lib/commands/asm/site.domain._js)通過Azure資源管理器。這可能意味着https://msdn.microsoft.com/en-us/library/azure/dn790568.aspx可能會提供所需的(現在是通用的)操作。 –

+0

我在這裏發佈我的問題http://stackoverflow.com/questions/32789231/azure-update-resource-property-with-rest-api – AAlferez

0

可以使用(Azure管理)Services API,Resources API或Azure RM PowerShell cmdlet完成此操作。

我發現使用Services API最簡單,因爲使用PowerShell登錄Microsoft帳戶時出現錯誤,以及爲了使用Resources API需要創建Azure RM應用程序作爲GlobalAdmin的荒謬需求。

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

需要全球性的管理員帳戶(共同管理不工作)。按照說明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',...] 
} 
+0

對於powershell命令至少你應該只包括自定義域而不是azurewebsites。淨值,請參閱http://stackoverflow.com/questions/27830895/setting-host-names-for-azure-websites-via-azure-powershell, –