且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

访问 azure 网站中上传的证书

更新时间:2023-02-08 23:07:16

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

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

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/