'.Net 5.0 - Authentication failed because the remote party sent a TLS alert: 'HandshakeFailure

I am using Windows Server 2012 R2 on my production server. I upgraded my webapplication to .Net 5.0 from 4.5. Now randomly facing this error, while communication of my front-end applications with the backend REST API built on .Net 5.0:

Exception[System.AggregateException: One or more errors occurred. (The SSL connection could not be established, see inner exception.) ---> System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception. ---> System.Security.Authentication.AuthenticationException: Authentication failed because the remote party sent a TLS alert: 'HandshakeFailure'. ---> System.ComponentModel.Win32Exception (0x80090326): The message received was unexpected or badly formatted.

--- End of inner exception stack trace ---

I have already used the below lines of code in my app:

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


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source