2016-04-25 7 views

答えて

2

はい、これを行うことができます。

1)プロジェクトにNuGet Web Sites Management Packageをインストールします。

2)Azureパブリッシュ設定ファイルを取得します(Powershell Get-AzurePublishSettingsFileなどを使用して)。後で必要になります(そのファイル内の管理証明書フィールドの値)。

2)WebSiteManagementClientをインスタンス化します。 Thatはコードの理解に役立つはずです。

3)次にコードは次のとおりです。私はちょうどテストし、それは動作します。まず、それがウェブスペース、ウェブスペースのそれぞれの内部に、その後のウェブサイトを一覧表示し、あなたが最も簡単にPowerShellを使用して行わ

public const string base64EncodedCertificate = "ManagementCertificateValueFromPublishSettingsFile"; 
    public const string subscriptionId = "AzureSubscriptionId"; 

    static SubscriptionCloudCredentials getCredentials() 
    { 
     return new CertificateCloudCredentials(subscriptionId, new X509Certificate2(Convert.FromBase64String(base64EncodedCertificate))); 
    } 
    static void Main(string[] args) 
    { 
     WebSiteManagementClient client = new WebSiteManagementClient(getCredentials()); 

     WebSpacesListResponse n = client.WebSpaces.List(); 
     n.Select(p => 
     { 
      Console.WriteLine("webspace {0}", p.Name); 
      WebSpacesListWebSitesResponse websitesInWebspace = client.WebSpaces.ListWebSites(p.Name, 
        new WebSiteListParameters() 
        { 
        }); 
      websitesInWebspace.Select(o => 
      { 
       Console.Write(o.Name);  

       return o; 
      }).ToArray(); 
      return p; 
     }).ToArray(); 

     Console.ReadLine(); 
     var configuration = client.WebSites.Get("WebSpaceName", "WebSiteName", new WebSiteGetParameters()); 

     configuration.WebSite.HostNames.Add("new domain"); 
     var resp = client.WebSites.Update("WebSpaceName", "WebSiteName", new WebSiteUpdateParameters() { HostNames = configuration.WebSite.HostNames }); 
     Console.WriteLine(resp.StatusCode); 
     Console.ReadLine(); 
    } 
+1

すべてを更新するのではなく、1つのカスタムドメイン名を追加するだけですか?それが更新されるたびにCNAMEチェックを実行しているようだが、カスタムドメインが20個ある場合は少し重い。 –

0

https://docs.microsoft.com/en-us/azure/app-service/scripts/app-service-powershell-configure-custom-domain

にウェブサイトのウェブスペースをコピーして貼り付ける必要があります。

$fqdn="<Replace with your custom domain name>" 
$webappname="mywebapp$(Get-Random)" 
$location="West Europe" 

# Create a resource group. 
New-AzureRmResourceGroup -Name $webappname -Location $location 

# Create an App Service plan in Free tier. 
New-AzureRmAppServicePlan -Name $webappname -Location $location ` 
-ResourceGroupName $webappname -Tier Free 

# Create a web app. 
New-AzureRmWebApp -Name $webappname -Location $location -AppServicePlan $webappname ` 
-ResourceGroupName $webappname 

Write-Host "Configure a CNAME record that maps $fqdn to $webappname.azurewebsites.net" 
Read-Host "Press [Enter] key when ready ..." 

# Before continuing, go to your DNS configuration UI for your custom domain and follow the 
# instructions at https://aka.ms/appservicecustomdns to configure a CNAME record for the 
# hostname "www" and point it your web app's default domain name. 

# Upgrade App Service plan to Shared tier (minimum required by custom domains) 
Set-AzureRmAppServicePlan -Name $webappname -ResourceGroupName $webappname ` 
-Tier Shared 

# Add a custom domain name to the web app. 
Set-AzureRmWebApp -Name $webappname -ResourceGroupName $webappname ` 
-HostNames @($fqdn,"$webappname.azurewebsites.net") 
関連する問題