Azure不返回上传的证书

时间:2016-09-27 09:50:13

标签: c# .net azure ssl certificate

我已经通过azure new portal上传了证书,而我在这里没有获得这些证书是我的代码

        var store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
        store.Open(OpenFlags.ReadOnly);
        X509Certificate2Collection certificates = store.Certificates;
        try
        {

        }
        finally
        {
            store.Close();
        }

        return certificates;

这些是我一直得到的证书

enter image description here

我也遵循了这篇文章https://azure.microsoft.com/en-us/blog/using-certificates-in-azure-websites-applications/

任何人都知道为什么我没有获得所有证书以及为什么我会获得这些证书?请帮忙

2 个答案:

答案 0 :(得分:1)

  

而不是为我刚刚收到这些4的所有证书进行geeting,而在本地环境中,我获得了在我的机器上安装的所有证书

在我的测试中,您的回复中的the article帮助我们在Azure网络应用中使用证书。但是,我们只能在以下条件下查询证书:

1)证书已上传到Azure网络应用程序
2)在Azure门户中设置WEBSITE_LOAD_CERTIFICATES,并将其值设置为证书指纹

与您在本地计算机上的测试不同,因为Azure Web应用程序在沙箱中运行。有关Azure Web应用程序沙箱的详细信息,请参阅this article

答案 1 :(得分:0)

好吧,我正在使用我在某个地方找到的这个功能并且工作正常。如果您已正确上传所有证书,可以尝试运行这段代码。我知道它看起来一样,但你无法说出来。

private X509Certificate2 GetStoreCertificate(string thumbprint)
    {
        List<StoreLocation> locations = new List<StoreLocation> { StoreLocation.CurrentUser, StoreLocation.LocalMachine };

        foreach (var location in locations)
        {
            Console.WriteLine("location: " + location.ToString());
            X509Store store = new X509Store("My", location);
            try
            {
                Console.WriteLine("Try, store.Open...");
                store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
                Console.WriteLine("store.Opened..." + store.Certificates.Count.ToString());

                foreach (X509Certificate2 cert in store.Certificates)
                {
                    Console.WriteLine("X509Certificate2 Thumbprint : " + cert.Thumbprint);
                }

                foreach (X509Certificate cert in store.Certificates)
                {
                    Console.WriteLine("X509Certificate Thumbprint : " + cert.Issuer);
                }

                X509Certificate2Collection certificates = store.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, false);
                Console.WriteLine("Finding certificate.." + certificates.Count.ToString());
                if (certificates.Count == 1)
                {
                    Console.WriteLine("Atleast one found!!!");
                    return certificates[0];
                }
            }
            finally
            {
                store.Close();
            }
        }
        throw new ArgumentException(string.Format("A Certificate with Thumbprint '{0}' could not be located.", thumbprint));
    }