'Https connection uses wrong certificate

I have C# HTTPS API server running on the local IP address. The idea is to call API methods from different IP address from the same subnetwork and authenticate using certificate. So, I issued self-signed CA certificate and client certificate. When I run application on localhost everything works well. But when I issued new certificate for IP address I use, the app runs using localhost certificate and client shows me that certificate is not trusted. I added test domain to the hosts file and linked it to my IP address - but when I issued CA certificate for this domain browser opens endpoints using localhost certificate. How to tell .NET application which certificate to use? Why even after I added test.com domain to the hosts file and issued CA cert for that domain, when I run application and open in browser test.com, it opens my app but shows cert for the localhost and tells that connection is not trusted?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source