In this article I will explain with an example, how to use TLS1.2 with .Net 2.0, .Net 3.0, .Net 3.5 and .Net 4.0 using C# and VB.Net.
The support for TLS 1.2 is available in .Net 4.5 onwards hence this article will demonstrate how to use it in other Frameworks such as Net 2.0, .Net 3.0, .Net 3.5 and .Net 4.0 without upgrading them.
 
 
What is TLS 1.2?
TLS 1.2 (Transport Layer Security version 1.2) is more secure than other cryptographic protocols such as SSL 2.0, SSL 3.0, TLS 1.0, and TLS 1.1.
 
 
Downloading .Net Framework 4.5
You will need to download and install the .Net Framework runtime on your computer where you are developing the program in Visual Studio or where the application is installed.
Note: There is no need to upgrade the project to .Net 4.5. Only .Net 4.5 Framework needs to be installed and then the following technique can be used for setting the TLS1.2 in projects using .Net 2.0, .Net 3.0, .Net 3.5 and .Net 4.0.
 
 
Namespaces
You will need to import the following namespace.
C#
using System.Net;
 
VB.Net
Imports System.Net
 
 
Using TLS1.2 in .Net 2.0, .Net 3.0, .Net 3.5 and .Net 4.0
Inside the Page Load event handler, first the Security Protocol is set.
Note: For higher .Net Framework version 4.5 and above, please refer Using TLS1.2 with HttpClient in C# and VB.Net.
 
Then, the JSON string is downloaded from an API using DownloadString method of the WebClient class and written to the Response.
C#
protected void Page_Load(object sender, EventArgs e)
{
    if (!this.IsPostBack)
    {
        ServicePointManager.Expect100Continue = true;
        ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
        string json = (new WebClient()).DownloadString("https://raw.githubusercontent.com/aspsnippets/test/master/Customers.json");
        Response.Write(json);
    }
}
 
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    If Not Me.IsPostBack Then
        ServicePointManager.Expect100Continue = True
        ServicePointManager.SecurityProtocol = CType(3072, SecurityProtocolType)
        Dim json As String = (New WebClient).DownloadString("https://raw.githubusercontent.com/aspsnippets/test/master/Customers.json")
        Response.Write(json)
    End If
End Sub
 
 
Screenshot
Using TLS1.2 in .Net 2.0, .Net 3.0, .Net 3.5 and .Net 4.0
 
 
Downloads


Other available versions