I am moving one asp.net app to azure environement.In the application we are using one X509Certificate2 while calling some webservices.I used cert.import method to import the certificate and then adding certificate object to client certificate property of service.It was working fine when we hosted our app on IIS servers.
This is how we are doing it :
abcservice service = new abcservice ();
`string CertificatePath = ConfigurationManager.AppSettings["CertificatePath"].ToString();
string certPwd = ConfigurationManager.AppSettings["CertificatePwd"].ToString();`
cert.Import(CertificatePath, certPwd , X509KeyStorageFlags.DefaultKeySet);
service.ClientCertificates.Add(cert);
But when we move to azure ,it stops working and start showing me cant find specified file at cert.import .
In web.config ,we have set following properties :
<clientCertificate findValue="abc-123.pqr.com" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName" />
<serviceCertificate>
<defaultCertificate findValue="xyz Gateway" storeLocation="LocalMachine" storeName="TrustedPeople" x509FindType="FindBySubjectName" />
<authentication certificateValidationMode="ChainTrust" revocationMode="Online" />
I have set up abc-123.pqr.com as DNS name for my website and i am able to access website using this URL and uploaded the certificate in azure portal against this URL.
What I have tried:
I came to know that MyStore is not working in Azure.So i am looking for some alternatives for that.I found one solution that how i can do this without using Import.
abcservice service = new abcservice ();
string CertificatePath =ConfigurationManager.AppSettings["CertificatePath"].ToString();
`string certPwd = ConfigurationManager.AppSettings["CertificatePwd"].ToString();`
X509Certificate2 cert = new X509Certificate2(CertificatePath , certPwd , X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable);
service.ClientCertificates.Add(cert);
Now it start adding certificate in service object but when i am calling service it start give me following Error :
Cannot find the X.509 certificate using the following search criteria: StoreName 'My', StoreLocation 'LocalMachine', FindType 'FindBySubjectName', FindValue 'abc-123.pqr.com'.
Please suggest how i can use it.Thanks in advance.