Click here to Skip to main content
15,891,906 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 :

C#
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 :

XML
<clientCertificate findValue="abc-123.pqr.com" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName" />
            <!--Need to provide Server certificate Details-->
            <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.
Posted
Comments
ZurdoDev 16-Jul-18 7:54am    
You have to load it as a file and then put the file in your site, not from a certificate store. It would probably work if you use an Azure VM and configured your site on that, but an Azure website won't have access to the Certificate Store.
tushi0407 16-Jul-18 8:06am    
yes..thats what,,,Azure website dont have certificate store.I have added certificate in the application and then dont know how i can store it so that web service using it can access that object.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900