Thursday, 8 February 2024

SecurityProtocolType TLS use in code without error for - Tls11, Tls12, and Tls13

 try { //try TLS 1.3

    ServicePointManager.SecurityProtocol = (SecurityProtocolType)12288

                                         | (SecurityProtocolType)3072

                                         | (SecurityProtocolType)768

                                         | SecurityProtocolType.Tls;

} catch (NotSupportedException) {

    try { //try TLS 1.2

        ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072

                                             | (SecurityProtocolType)768

                                             | SecurityProtocolType.Tls;

    } catch (NotSupportedException) {

        try { //try TLS 1.1

            ServicePointManager.SecurityProtocol = (SecurityProtocolType)768

                                                 | SecurityProtocolType.Tls;

        } catch (NotSupportedException) { //TLS 1.0

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;

        }

    }

}