gpt4 book ai didi

azure - 如何通过 Management Rest API 在 Azure Web Apps 上设置 SSL 绑定(bind)?

转载 作者:太空宇宙 更新时间:2023-11-03 13:24:38 25 4
gpt4 key购买 nike

我们正在使用网站管理 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 绑定(bind)。

enter image description here

有人有关于如何添加调整此主机名的 SSL 状态的经验/代码示例吗?

最佳答案

我希望它能对某人有所帮助。

安装管理包

Install-Package Microsoft.Azure.Management.Fluent

Setup AAD, Setup Key and Password

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

Setup Access level under subscription for specific app

https://learn.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" );
}
}

关于azure - 如何通过 Management Rest API 在 Azure Web Apps 上设置 SSL 绑定(bind)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36828116/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com