0
votes
        using (WebClient wc = new WebClient()) {
            string pageSourceCode = webclient.DownloadString("https://hostname");
        }

I have added the certificate (self-signed) used on the web server to "Trusted Root Certification Authorities" on local computer, but still get the exception "The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.", how come?

Edit: Seems to be working now after removing and then reinstalling the certificate.

1

1 Answers

0
votes

If the certificate is self-signed, it doesn't matter where you put it. You are not a CA, you are not trusted for .NET.

What you can do, however, is bypass the check, namely by adding

ServicePointManager.ServerCertificateValidationCallback += (s, c, ch, ssl) => true;

But you should take into account the security risk this comes with.