4

我正在使用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;
}

但添加证书后,我无法在门户中看到添加到站点的证书: 没有向网站添加 SSL 证书

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

此外,如果我转到Azure 资源管理器并导航到该站点并查找 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 证书分配给站点?

4

1 回答 1

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 对象中的所有参数都是必需的。您能否验证那里需要哪些属性?(我从资源浏览器中获取了值)

于 2016-02-02T13:18:52.020 回答