我正在使用Microsoft.WindowsAzure.Management.WebSites 4.4.2-prerelease
库来创建/修改Azure WebApps。我可以创建应用程序,可以更改设置,可以添加自定义域名。下一步是添加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;
}
Cert是通配符证书,已上传。如果我使用新门户将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证书?
答案 0 :(得分:1)
从https://github.com/davidebbo/AzureWebsitesSamples/issues/2我引用@trailmax对该问题的回答以及将来的参考文献。
我设法让它运转起来。主机名将添加 CreateOrUpdateSiteHostNameBindingAsync()而不是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);
虽然我不确定所有的参数 HostNameBinding对象是必需的。你能否验证一下 那里需要属性吗? (我从资源中获取了值 资源管理器)