gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 20:49:39 25 4
gpt4 key购买 nike

我构建了一个引用 Windows Azure 管理库的 Azure Web 作业控制台。我尝试使用公共(public)设置方法来验证我的应用程序。

该程序在我的本地运行良好,但在 Azure Web 作业上失败并出现 X509Certificates 错误。

这就是我为网络作业程序所做的。

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

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

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

  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)

执行时出现异常:

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。以下是您需要执行的操作:

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

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

关于c# - Web 作业上的 Windows Azure 管理库认证错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23330863/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com