WebRole中的证书列表为空

时间:2013-08-29 19:00:27

标签: azure azure-web-roles certificate-store

我正在我的网络应用程序中编写代码,该代码需要列出并搜索安装在Web角色上的特定证书。 这是我的代码

// using System.Security.Cryptography.X509Certificates;

var store = new X509Store() ;
store.Open(OpenFlags.ReadOnly);
LoggingService.Info(String.Format(
     "{0} Certificate(s) are found in store",store.Certificates.Count));
for(int index=0;index<store.Certificates.Count;index++)
{
    LoggingService.Info(String.Format(
        "Subject:{0}, Thumbprint:{1}",store.Certificates[index].Subject,
        store.Certificates[index].Thumbprint));
}
_Certificate = store.Certificates.Find(
     X509FindType.FindByThumbprint, this.CertificateThumbprint, false)[0];

现在问题是,即使通过门户网站在Web角色中添加了证书,也存在于配置文件中。 store.Certificates.Count为零。此代码在模拟器中运行完美,但不知何故无法列出Web角色证书。如何访问Web角色上安装的证书?

1 个答案:

答案 0 :(得分:0)

知道了,我没有在Store类中提供任何商店名称和位置,并且假设它将在每个商店和位置进行搜索,但它不是这样的。然后我提供了商店名称和位置,现在系统能够找到证书。