When calling an OData service from inside my ASP.NET MVC application, the call always fails with the following exception:
The remote certificate is invalid according to the validation procedure
The OData service I’m connecting to is available through HTTPS so I would guess that something is wrong with the SSL certificate.
Let’s walk through the checklist:
- Hostname matches the name used in the certificate: OK
- Certificate is not expired: OK
- Encryption level is high enough: OK
- The full certificate chain is trusted: OK
Mmm, strange. Everything seemed fine. And when I browsed to the OData service directly from the browser, I could get all the data as I would expect.
In the end I figured out that I had to give the MVC application access to the private key of the certificate.
Following steps fixed the problem:
- Export the certificate from the OData Service host(don’t forget to export the private key as well).
- Open MMC and load the Certificates snap-in.
- Import the certificate into the "Local Computer" account on the server where the ASP.NET MVC application is hosted. Make sure to check "Allow private key to be exported"
- Give your IIS 7.5 Application Pool's identity Full Trust access to the certificate.