Use a client certificate in a WebJob

十年热恋 提交于 2020-01-23 09:48:13

问题


I have a web job running on an Azure web app. I web job needs to access a client certificate for outbound traffic encryption.

How can I access a client certificate from an Azure web job? I tried installing the certificate on the host web app and access the certificate this way:

    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();
        }
    }

This unfortunately didn't work as the certificate could not be found. I am stuck.


回答1:


Oh got it! I followed all the steps in this article but I missed an important step: You must add a setting named "WEBSITE_LOAD_CERTIFICATES" to the web app "APP SETTINGS" which will force the web app to load all certificates.



来源:https://stackoverflow.com/questions/41707325/use-a-client-certificate-in-a-webjob

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!