I'm using Sitecore 9.2
scaled environment on Azure, and am trying to make a .Net core 2.2 project published on azure app service connects to XConnect which is also on Azure, am following this link from Sitecore documentation.
but this time when I tried this code from this link. To get the certificate from Azure:
X509Store certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser);
certStore.Open(OpenFlags.ReadOnly);
X509Certificate2Collection certCollection = certStore.Certificates.Find(
X509FindType.FindByThumbprint,
// Replace below with your certificate's thumbprint
"E661583E8FABEF4C0BEF694CBC41C28FB81CD870",
false);
I found the certificate. but when I tried to connect using this connection string:
var xdbCollectionCert = "StoreName=My;StoreLocation=CurrentUser;FindType=FindByThumbprint;FindValue={thumbprintvalue}";
var xdbClient = "{XConnectName}"
var odataEndpoint = xdbClient + "/odata";
var collectionEndpoint = xdbClient + "/configuration";
var options = CertificateHttpClientHandlerModifierOptions.Parse(xdbCollectionCert);
var certificateModifier = new CertificateHttpClientHandlerModifier(options);
It gives an error that certificate not found, although I added the certificate in TLS and added WEBSITE_LOAD_CERTIFICATES
Sitecore.XConnect.XdbCollectionUnavailableException: The certificate was not found. Store: My, Location: CurrentUser, FindType: FindByThumbprint, FindValue: {thumbprintValue}, InvalidAllowed: False.
at Sitecore.Xdb.Common.Web.CertificateHttpClientHandlerModifier.Process(HttpClientHandler handler)
at Sitecore.Xdb.Common.Web.CommonWebApiClient`1.CreateRequestHandler()
Can someone please advise how can I changeCertificateHttpClientHandlerModifier
to X509Certificate2
? or why the code can not find the certificate?
CertificateWebRequestHandlerModifier
, but I can find aCertificateHttpClientHandlerModifier
, and that one basically ends up fetching the certificate the same way you have successfully done (from what I've seen in the source). What happens if you useCertificateHttpClientHandlerModifier
instead?CertificateHttpClientHandlerModifierOptions
I edited the question, but do you have any idea why the code can not find the certificate?CertificateHttpClientHandlerModifier
inherints fromIHttpClientHandlerModifier
. Maybe you could try to create your own implementation of this interface, get the certificate in theProcess()
method using the code you know works, then set the certificate to the handler provider as input to this method:handler.ClientCertificateOptions = ClientCertificateOption.Manual; handler.ClientCertificates.Add(yourCertificate);
.