none
Request aborted: Could not create SSL/TLS secure channel RRS feed

  • Question

  • Hi everyone,

    First, some background: I'm maintaining a content filter that was built with C# / .NET 4.6.1 / .NET Standard

    I'm currently running into an issue where .NET fails to open a secure channel to a particular website. The URL I'm trying to access with C# is https://portal.worldpay.us

    Here's the error I'm getting:

    Exception: System.AggregateException: One or more errors occurred. ---> System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.
       at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
       at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar)
       --- End of inner exception stack trace ---
       --- End of inner exception stack trace ---
       at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
       at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
       at System.Threading.Tasks.Task`1.get_Result()
       at InternetTesting.Program.Main(String[] args) in c:\users\kent friesen\source\repos\InternetTesting\InternetTesting\Program.cs:line 22
    ---> (Inner Exception #0) System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.
       at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
       at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar)
       --- End of inner exception stack trace ---<---
    The portal.worldpay.us is encrypted with TLSv1 and an AES-128SHA cipher, according to OpenSSL.

    Code which replicates the problem:

    class Program
    {
        static void Main(string[] args)
        {
            HttpClient client = new HttpClient();
            HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Get, "https://portal.worldpay.us");
    
            HttpResponseMessage response = null;
    
            try
            {
                response = client.SendAsync(message).Result;
            }
            catch(Exception ex)
            {
                Console.WriteLine("Exception: {0}", ex);
            }
    
            if (response != null)
            {
                Console.WriteLine("Response {0}", response.StatusCode);
            }
    
            Console.ReadKey();
        }
    }

    At first, I thought it was an Schannel problem, but now I'm not sure, because no Schannel error appears in event viewer, and I am able to access the site with IE11 and Edge just fine.

    Does anyone have any ideas what the problem might be? I'd be inclined to say there's a bug somewhere in the .NET software stack, but I'd like to be proven wrong.

    Thanks

    Edit: Tested with .NET 4.6.1, 4.7.2 and got the same results. Testing with .NET Core 2.0 worked, but that's not an option for a short-term fix.
    Wednesday, June 6, 2018 7:39 PM

All replies

  • Hi Kent Friesen,

    Thank you for posting here.

    1. If your .NET framework version is not the .NET framework 4.5, you could use following code.

    ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;

    For more details, please refer to the following link.

    https://stackoverflow.com/questions/2859790/the-request-was-aborted-could-not-create-ssl-tls-secure-channel

    2. Maybe you do not set TLS in your code. You could try the following code instead.

     ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

    For more details, please refer to the thread in so.

    https://stackoverflow.com/questions/32994464/could-not-create-ssl-tls-secure-channel-despite-setting-servercertificatevalida

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, June 13, 2018 12:51 AM
    Moderator
  •   ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

    i has set protocol to tls12,it work fine in window10,buy win7 or window 2008 still has its error when httpwebrequest connect to TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,256,TLS1.2

    can your help me ?%>_<%

    Thursday, August 16, 2018 2:14 AM
  • in Windows XP, in Windows 7, you must add this at the beginning:

    ServicePointManager.Expect100Continue = true;
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
    Wednesday, September 5, 2018 10:30 AM
  • My app is deployed at Win2012R2, and tries to connect to a HTTPS site with the same error. Tried to set 

    ServicePointManager.Expect100Continue = true;
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

    - no luck. Meanwhile, under Win10 this code works flawlessly with the same HTTPS. What am I doing wrong with this code?

    Sunday, November 22, 2020 6:16 PM