在 azure 网站中访问上传的证书 [英] Accessing uploaded certificates in azure web sites

查看:26
本文介绍了在 azure 网站中访问上传的证书的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用网络角色时,我只是在 azure 门户中上传证书,我能够看到它.现在我已经切换到 azure 中的网站,我在 azure 管理门户中上传了证书,但我的代码确实如此根本看不到.

When I was using the web role I was just uploading the certificate in azure portal and I was able to see it .Now I have switched to the website in azure and I uploaded the certificate in the azure management portal but my code does not see it at all.

我们是否需要做一些配置或其他方式来访问 azure 网站中上传的证书.

Is there some configurations we need to do or some other way to access uploaded certs in azure web sites.

这就是我尝试访问上传的证书的方式.

This is how I am trying to access the uploaded cert .

private List<string> GetAvailableCertificatesFromStore()
{
    var list = new List<string>();
    var store = new X509Store(StoreName.My,StoreLocation.LocalMachine);
    store.Open(OpenFlags.ReadOnly);

    try
    {
        foreach (var cert in store.Certificates)
        {
            // todo: add friendly name
            list.Add(string.Format("{0}", cert.Subject));
        }
    }
    finally
    {
        store.Close();
    }

    return list;
}

推荐答案

更新 - 2015 年 7 月 23 日:此答案现已过时(但在提供时它是正确的).请参阅下面 S Armstrong 的回答.

Azure 云服务(Web/Worker 角色)Azure 网站 中的工作方式不同.在 Azure 云服务中,当您通过管理门户上传证书并在您的角色属性中指定该证书的指纹和安装位置时,当您的角色部署在 VM 中时,负责它的结构控制器也会自动为您安装这些证书.这就是上面的代码在 web 角色中工作的原因.

Things work differently in Azure Cloud Services (Web/Worker Roles) and Azure Websites. In Azure Cloud Services when you upload a certificate through management portal and specify that certificate's thumbprint and install location in your role's properties, when your role is deployed in a VM the fabric controller responsible for it also installs these certificates automatically for you. This is the reason the code above works in a web role.

在网站中,您需要自己执行此操作.不幸的是,由于 Azure 网站的安全限制,您无法在证书存储中安装证书.要使用证书,您需要将证书的 PFX 文件与您的代码一起包含并使用该证书文件.您无法在证书存储中安装证书.

In website, you would need to do this on your own. Unfortunately because of security restrictions in an Azure website, you just can't install a certificate in certificate store. To work with certificates, you would need to include the certificate's PFX file along with your code and work with that certificate file. You can't install the certificate in certificate store.

在我对 Azure 网站和证书所做的任何小工作中,我发现证书仅在 PFX 文件包含在 AppData 文件夹中时才有效.此外,您可能会遇到 CryptographicException: The system cannot find the file specified 之类的错误.如果遇到此错误,您可能会发现这篇博文很有用:http://blog.tylerdoerksen.com/2013/08/23/pfx-certificate-files-and-windows-azure-websites/

In whatever little work I have done with Azure Website and Certificates, I have found that the certificate only works if the PFX file is included in AppData folder. Also you may run into errors like CryptographicException: The system cannot find the file specified. If you run into this error, you may find this blog post useful: http://blog.tylerdoerksen.com/2013/08/23/pfx-certificate-files-and-windows-azure-websites/

这篇关于在 azure 网站中访问上传的证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆