How to force asp.net to use TLS 1.2 while making the HTTP request?

Programming, error messages and sample code > ASP.NET
In .NET 4.0 default transport level security standard is TLS 1.1. The solution is to upgrade site to .NET 4.6 or above. In this framework version TLS 1.2 is a default cryptographic standard.
 
But what if you can't upgrade your application to latest .NET framework, you can use below code.  The following code will make TLS 1.2 default, make sure to execute it before making a connection to secured resource:
 
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;