在WebJob中使用客户端证书

GET*_*Tah 3 c# ssl azure azure-webjobs

我有一个在Azure Web应用程序上运行的Web作业。我的Web作业需要访问客户端证书以进行出站流量加密。

如何从Azure Web作业访问客户端证书?我尝试将证书安装在主机Web应用程序上,并通过以下方式访问证书:

    private static X509Certificate2 LoadCertificateFromStore(string certificateThumbprint){
        var store = new X509Store(StoreLocation.CurrentUser);
        try {
            store.Open(OpenFlags.ReadOnly);
            var certCollection = store.Certificates;
            var currentCertificate = certCollection.Find(X509FindType.FindByThumbprint, certificateThumbprint, false);
            if (currentCertificate.Count == 0)
                throw new InvalidOperationException("Could not find certificate " + certificateThumbprint);
            return currentCertificate[0];
        } finally{
            store.Close();
        }
    }
Run Code Online (Sandbox Code Playgroud)

不幸的是,由于找不到证书,因此无法正常工作。我被困住了。

GET*_*Tah 5

哦,明白了!我遵循了本文中的所有步骤但是错过了重要的步骤:您必须将名为“ WEBSITE_LOAD_CERTIFICATES”的设置添加到Web应用程序“ APP SETTINGS”,这将强制Web应用程序加载所有证书。