0

We have Azure Web App service, which is configured to have a custom domain say "https://test.contosa.com". I'm using the below code in my web app to retrieve the certificate from store.

using (X509Store certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser))
{
    certStore.Open(OpenFlags.ReadOnly);

    X509Certificate2Collection certCollection = certStore.Certificates.Find(
                                X509FindType.FindByThumbprint,
                                "<<MY_CERTIFICATE_THUMBPRINT>>",
                                false);

    X509Certificate2 certificate = certCollection.OfType<X509Certificate2>().FirstOrDefault();

    if (certificate != null)
    {
        // Using the certificate here for generating and reading token
    }
}

Now when I use the web app url "http://test.azurewebsites.net", I can able to fetch the certificates.

We have added the certificate binding for the custom domain based on the this link.

But when I use the custom domain "https://test.contosa.com", it's unable to find the certificate from store. How to search the certificate for custom domain?. Thanks in advance.

  • Have you referred to https://learn.microsoft.com/en-us/azure/app-service/configure-ssl-certificate-in-code? – Jim Xu Mar 24 '21 at 05:07
  • Have you added the app setting `WEBSITE_LOAD_CERTIFICATES=`? – Jim Xu Mar 24 '21 at 06:11
  • Yes I've referred the above link for adding the certificate and I have the app setting WEBSITE_LOAD_CERTIFICATE with the thumbprint. – Manivannan Mar 24 '21 at 07:31
  • Could you please tell me what error you get? – Jim Xu Mar 24 '21 at 08:52
  • I'm not getting any error. When using the azure web app url, I can able to fetch the certificate from store. If I use the custom domain, I'm unable to locate the certificate from store. – Manivannan Mar 24 '21 at 09:40
  • According to my test, I can get certificate. My code : https://controlc.com/71cab750 My result: https://imgur.com/a/9GOXJBh – Jim Xu Mar 25 '21 at 01:48

0 Answers0