Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8647011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:57:33+00:00 2026-06-12T12:57:33+00:00

I wrote a C# program that uses HttpWebRequest to connect to an HTTPS site.

  • 0

I wrote a C# program that uses HttpWebRequest to connect to an HTTPS site. The GetResponse() method throws an exception:

SystemError: The underlying connection was closed: Could not establish
trust relationship for the SSL/TLS secure channel.

I’m able to connect to the same website using curl.exe --cacert CAFile.pem. I’d like to be able use the same trusted CA certificates from the C# program.

How can I get HttpWebRequest to use this CA certificate file (or an X509CertificateCollection containing certificates parsed from it)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T12:57:34+00:00Added an answer on June 12, 2026 at 12:57 pm

    Try setting your ServerCertificateValidationCallback to use this:

    public static bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
    {
        if (sslPolicyErrors == SslPolicyErrors.None)
        return true;
    
        X509Chain privateChain = new X509Chain();
        privateChain.ChainPolicy.RevocationMode = X509RevocationMode.Offline;
    
        X509Certificate2 cert2 = new X509Certificate2(certificate);
        X509Certificate2 signerCert2 = new X509Certificate2(@"C:\MyCACert.PEM");
    
        privateChain.ChainPolicy.ExtraStore.Add(signerCert2);       
        privateChain.Build(cert2);
    
        bool isValid = true;
    
        foreach (X509ChainStatus chainStatus in privateChain.ChainStatus)
        {
            if (chainStatus.Status != X509ChainStatusFlags.NoError)
            {
                isValid = false;
                break;
            }
        }
    
        return isValid;
    }
    

    I have not had an opportunity to test this, so let me know if you encounter any errors and I’ll modify the answer if needed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a small program that uses Mechanize to traverse a site. I want
I wrote a C# program that uses the mouse and it works perfectly. I
I wrote a program on Ubuntu 11.04 that uses freeglut. It worked fine. Then
I wrote a program that uses OLE and it was working fine until I
The problem is this: I wrote a simple program that uses FFMPEG. compile as
I wrote a form based program in C# that uses MS access database to
I wrote a program that uses builtin function bin(), but this function is new
I wrote a program that uses a QWebPage to retrieve websites. Is there a
I wrote a program that uses bitarray 0.8.0 to write bits to a binary
This is question about Objective-C. I wrote the program that uses regular expression with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.