问题
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