Web作业上的Windows Azure管理库认证错误

我构建了一个Azure Web作业控制台,它引用了Windows Azure管理库。 我尝试使用公共设置方法validation我的应用。

该程序在我的本地工作正常,但在使用X509Certificates错误的Azure Web作业上失败。

这就是我为网络工作计划所做的工作。

  1. 从https://windows.azure.com/download/publishprofile.aspx下载发布设置文件

  2. 在控制台应用程序上,通过从设置文件中复制并粘贴subscriptionId和cert字符串来创建凭证。

    new CertificateCloudCredentials( subscriptionId, new 509Certificate2(Convert.FromBase64String(base64EncodedCertificate))); 
  3. 在Azure Web Job上部署并尝试“按需运行”。

  4. 错误

     at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr) at System.Security.Cryptography.X509Certificates.X509Utils._LoadCertFromBlob(Byte[] rawData, IntPtr password, UInt32 dwFlags, Boolean persistKeySet, SafeCertContextHandle& pCertCtx) at System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromBlob(Byte[] rawData, Object password, X509KeyStorageFlags keyStorageFlags) at System.Security.Cryptography.X509Certificates.X509Certificate..ctor(Byte[] data) at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(Byte[] rawData) 

执行时出现exception:

 System.Security.Cryptography.CryptographicException, The system cannot find the file specified. 

我建议从这篇博文开始: http : //blog.tylerdoerksen.ca/2015/11/29/pfx-certificate-files-and-azure-web-apps/ 。 虽然这篇博文是关于Azure网站而不是Azure Webjobs本身,但我倾向于相信你的问题是因为这个。 事实上,我遇到了与Azure网站完全相同的问题。

但是,为了使用博客文章中概述的解决方案,您不能按certstring使用发布设置文件中的certstring 。 这是你需要做的:

  1. 通过另一个控制台应用程序,首先创建一个X509证书并将其安装在本地计算机的证书存储中。
  2. 以PFX格式导出证书并提供密码。
  3. 将此PFX证书作为解决方案的一部分。 对于Azure网站,我们必须将此文件包含在App_Data文件夹中,不确定在Webjob的情况下将其包含在何处。 您可以尝试使它存在于bin文件夹中。
  4. 阅读此文件并尝试使用博客文章中指定的语法创建X509证书的实例(并在此处复制):

     var cert = new X509Certificate2(pfxFile, "myPassword", X509KeyStorageFlags.MachineKeySet);