2

我们正在使用网站管理 SDK 在 Azure 上构建自动化部署。我们目前设法通过代码将主机名添加到 Web 应用程序。

using (websiteClient)
{
     var configuration = websiteClient.WebSites.Get(webspace, WebsiteName + "-" + Version, new WebSiteGetParameters());

     configuration.WebSite.HostNames.Add(ClientName + "." + DnsZoneName);

     var response = websiteClient.WebSites.Update(webspace, WebsiteName + "-" + Version, new WebSiteUpdateParameters() { HostNames = configuration.WebSite.HostNames });
}

但是我们无法让 HostNameSslStates 正常工作。以类似的方式,我们尝试为该网站添加 SSL 状态。

 configuration.WebSite.HostNameSslStates.Add(new WebSite.WebSiteHostNameSslState() { Name = ClientName + "." + DnsZoneName, SslState = WebSiteSslState.SniEnabled, Thumbprint = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" });

但这不会导致 Azure 门户上的 SSL 绑定。

在此处输入图像描述

谁有任何经验/代码示例如何添加调整此主机名的 SSL 状态?

4

1 回答 1

3

我希望它会帮助某人。

安装管理包

安装包 Microsoft.Azure.Management.Fluent

设置 AAD、设置密钥和密码

https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal#get-application-id-and-authentication-key

在特定应用的订阅下设置访问级别

https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal

var creds = new AzureCredentialsFactory().FromServicePrincipal( APPLICATION_ID, KEY_PASSWORD, DIRECTORY_ID, AzureEnvironment.AzureGlobalCloud);
var azure = Azure.Authenticate(creds).WithSubscription(SUSCRIPTION_ID);
var apps = azure.WebApps.List( );
foreach( var app in apps )
{
    if( app.Name == REQUIRED_APP_NAME  )
    {
        Console.WriteLine( app.Name );
        Console.WriteLine( $"Applying domain name {SUB_DOMAIN}.{DOMAIN}" );

        var updatedApp = app.Update( )
                                      .DefineHostnameBinding( )
                                      .WithThirdPartyDomain( DOMAIN )
                                      .WithSubDomain( SUB_DOMAIN )
                                      .WithDnsRecordType( CustomHostNameDnsRecordType.CName )
                                      .Attach( )
                                      .Apply( );

         Console.WriteLine( $"Applying SSL for {SUB_DOMAIN}.{DOMAIN}" );

         await azure
                    .WebApps
                    .Inner
                    .CreateOrUpdateHostNameBindingWithHttpMessagesAsync(       
                        RESOURCE_GROUP,
                        app.Name,
                        $"{SUB_DOMAIN}.{DOMAIN}",
                        new HostNameBindingInner( 
                            azureResourceType: AzureResourceType.Website,
                            hostNameType: HostNameType.Verified,
                            customHostNameDnsRecordType: CustomHostNameDnsRecordType.CName,
                            sslState: SslState.SniEnabled,
                            thumbprint: EXISTING_THUMBPRINT ) );

         Console.WriteLine( "OK" );
    }
}
于 2018-05-06T02:39:41.783 回答