1

I am having an issue when downloading a file from a https connection.

Everything works as expect for a while. Then after a seemingly random (although short) interval the downloads start failing with the following exception:

The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel. ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.

The ca (Go Daddy) is trusted. It works for a dozen or so downloads and then gets this error. Once the error starts happening only a restart of the service doing the downloads will make it work again. Of course that functioning is short lived.

The code doing the download is dead simple :

private void DownloadFileTo(string targetPath)
{
    using (WebClient client = new WebClient())
    {
        string finalURL = CombineURLParts();
        client.DownloadFile(finalURL, targetPath);
    }
}

I am tearing my hair out trying to make this work. I have attempted to disable cert validation using ServicePointManager.ServerCertificateValidationCallback, but the error still occurs. I am logging the cert in the handler, but everything looks identical between the downloads that work, and the ones that do not.

Any ideas?

athelred
  • 21
  • 2

0 Answers0