gpt4 book ai didi

c# - 通过 C# Azure 管理库将 SSL 绑定(bind)添加到 Azure 网站

转载 作者:行者123 更新时间:2023-11-30 12:42:42 24 4
gpt4 key购买 nike

我正在使用 Microsoft.WindowsAzure.Management.WebSites 4.4.2-prerelease 库来创建/修改 Azure WebApp。我可以创建应用程序,可以更改设置,可以添加自定义域。下一步是添加 SSL 证书。我是这样做的:

public async Task<WebSiteUpdateResponse> UpdateSslCertificate(String sitename)
{
var updateParameters = new WebSiteUpdateParameters()
{
HostNameSslStates = new List<WebSiteUpdateParameters.WebSiteHostNameSslState>()
{
new WebSiteUpdateParameters.WebSiteHostNameSslState()
{
ToUpdate = true,
Name = "mysubdomain.mydomain.com",
SslState = WebSiteSslState.SniEnabled,
Thumbprint = "blbhbblblblblblblbMyCertTHUMBPRINT",
},
},
};
var updateResult = await client.WebSites.UpdateAsync("Default-NorthEuropewebspace", sitename, updateParameters);
return updateResult;
}

但是添加证书后,我在门户中看不到添加到站点的证书: No SSL Cert added to the site

证书是通配符证书并且已上传。如果我使用新门户将 SSL 证书添加到网站 - 我可以毫无问题地做到这一点,因此这不是定价问题。

如果我去 Azure Resource Manager导航到该网站并查找 SslStates,我得到了:

"hostNameSslStates": [
{
"name": "mysubdomain.mydomain.com",
"sslState": 0,
"ipBasedSslResult": null,
"virtualIP": null,
"thumbprint": null,
"toUpdate": null,
"toUpdateIpBasedSsl": null,
"ipBasedSslState": 0,
"hostType": 0
},
{
"name": "testingcreation.azurewebsites.net",
"sslState": 0,
"ipBasedSslResult": null,
"virtualIP": null,
"thumbprint": null,
"toUpdate": null,
"toUpdateIpBasedSsl": null,
"ipBasedSslState": 0,
"hostType": 0
},
{
"name": "testingcreation.scm.azurewebsites.net",
"sslState": 0,
"ipBasedSslResult": null,
"virtualIP": null,
"thumbprint": null,
"toUpdate": null,
"toUpdateIpBasedSsl": null,
"ipBasedSslState": 0,
"hostType": 1
}
],

因此添加了新证书,仅状态为 0 (WebSiteSslState.Disabled),并且未存储指纹。

我做错了什么吗?如何将 SSL 证书分配给网站?

最佳答案

来自https://github.com/davidebbo/AzureWebsitesSamples/issues/2我引用了 @trailmax 对该问题的回答,以供将来引用。

I have managed to get it working. Host names are to be added by CreateOrUpdateSiteHostNameBindingAsync() rather than site.HostNames:

       var binding = new HostNameBinding()
{
Location = "North Europe",
Name = hostName,
CustomHostNameDnsRecordType = CustomHostNameDnsRecordType.CName,
HostNameType = HostNameType.Verified,
SiteName = siteName,
Type = "Microsoft.Web/sites/hostNameBindings",
};
var result = await websiteClient.Sites.CreateOrUpdateSiteHostNameBindingAsync(resourceGroupName,
siteName, hostName, binding);
site = websiteClient.Sites.GetSite(resourceGroupName, siteName);

site.HostNameSslStates.Add(new HostNameSslState
{
Name = hostName,
Thumbprint = certificate.Thumbprint,
SslState = SslState.SniEnabled,
ToUpdate = true,
});

site = await websiteClient.Sites.CreateOrUpdateSiteAsync(resourceGroupName,
siteName, site);

Though I'm not sure about all the parameters in HostNameBinding object are required. Can you please verify what properties are required there? (I took the values from Resource Explorer)

关于c# - 通过 C# Azure 管理库将 SSL 绑定(bind)添加到 Azure 网站,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32849003/

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