简体   繁体   English

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

[英]Windows Azure Management Libraries Certification Error on Web Jobs

I built a Azure web job console which is referring Windows Azure Management Libraries. 我构建了一个Azure Web作业控制台,该控制台引用了Windows Azure管理库。 I tried to authenticate my app by using public setting approach. 我尝试使用公共设置方法对我的应用进行身份验证。

The program is working fine on my local, but failing on Azure Web Jobs with X509Certificates error. 该程序在我的本地计算机上运行良好,但在带有X509Certificates错误的Azure Web作业上失败。

This is how I did for the web job program. 这就是我为网络工作计划所做的。

  1. Downloaded publish setting file from https://windows.azure.com/download/publishprofile.aspx https://windows.azure.com/download/publishprofile.aspx下载了发布设置文件

  2. On console app, create credential by copy & paste subscriptionId and cert string from the setting file. 在控制台应用程序上,通过复制并粘贴设置文件中的subscriptionId和证书字符串来创建凭据。

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

  4. The error 错误

     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 while executing: 执行时发生异常:

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

I would suggest starting with this blog post: http://blog.tylerdoerksen.ca/2015/11/29/pfx-certificate-files-and-azure-web-apps/ . 我建议从此博客文章开始: http : //blog.tylerdoerksen.ca/2015/11/29/pfx-certificate-files-and-azure-web-apps/ Though this blog post is about Azure Websites and not Azure Webjobs per se however I'm inclined to believe that your problem is because of this. 尽管此博客文章本身是关于Azure网站而不是Azure Webjobs的,但是我倾向于认为您的问题是因为这个。 In fact, I ran into exact same problem with Azure Websites. 实际上,我遇到了与Azure网站完全相同的问题。

However in order to use the solution outlined in the blog post, you can't use the certstring from the publish setting file as is. 但是,为了使用博客文章中概述的解决方案,不能按certstring使用发布设置文件中的certstring Here's what you would need to do: 这是您需要做的:

  1. Through another console application, first create an X509 certificate and install it in the certificate store of your local computer. 通过另一个控制台应用程序,首先创建一个X509证书并将其安装在本地计算机的证书存储中。
  2. Export the certificate in PFX format and provide a password. 以PFX格式导出证书并提供密码。
  3. Include this PFX certificate as a part of your solution. 将此PFX证书作为解决方案的一部分。 In case of Azure Websites, we had to include this file in App_Data folder, not sure where you will include it in case of Webjob. 如果是Azure网站,则必须将此文件包含在App_Data文件夹中,不确定如果使用Webjob时将在哪里包含该文件。 You can try so that it is present in the bin folder. 您可以尝试使它出现在bin文件夹中。
  4. Read this file and try to create an instance of X509 Certificate using the syntax specified in the blog post (and copied here): 阅读此文件,并尝试使用博客文章中指定的语法(并在此处复制)创建X509证书的实例:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM