0
votes

I have an Azure App Service that uses ACS to log in, it is an MVC 5 site if that helps at all.

It needs a certificate, let's say the thumbprint is AF47AF47AF47AF47AF47AF47AF47AF47AF47AF47

I uploaded it via the portal:enter image description here

Then I added the Application Setting > App Setting of WEBSITE_LOAD_CERTIFICATES/*: enter image description here

Works great locally (of course) - when I load it up on Azure, I get:

Could not find service certificate: AF47AF47AF47AF47AF47AF47AF47AF47AF47AF47in the My store on CurrentUser HandlingInstanceID: 74429bcf-4e02-4e28-a261-329bf831f7ce An exception of type 'System.ArgumentNullException' occurred and was caught. ---------------------------------------------------------------------------- 06/27/2017 22:21:44 Type : System.ArgumentNullException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 Message : Value cannot be null.

(Stack trace unavailable)

Any idea what I am missing? I have tried loading the certificate in my Application_Start() as well with no luck - I can post that code if anyone wants.

1
Hi, did you solve this? I have exactly the same problem and I haven't found a solution yet.Robini

1 Answers

2
votes

It seems that you’d like to upload your certificate to the certificates collection in Azure app service web app and consume it in your MVC application from your site’s personal certificate store, I upload a certificate and add an app setting named WEBSITE_LOAD_CERTIFICATES, and than I can access the certificate in my application using the following code, please refer to it.

var thumbprint = "xxxxxxxxxxxxxx";

X509Certificate2 retVal = null;

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

X509Certificate2Collection certCollection = certStore.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, false);

if (certCollection.Count > 0)
{
    retVal = certCollection[0];
}

certStore.Close();

remote debug web app and it works as expected.

enter image description here

Besides, this article explained with detailed steps using Certificates in Azure App Services, please refer to it.