In this article I will explain with an example, how to use TLS1.2 in projects using .Net 2.0, .Net 3.0, .Net 3.5 and .Net 4.0 with C# and VB.Net.
But, the support for TLS 1.2 is available in .Net 4.5 onwards and hence this article will demonstrate how to use it in projects 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.
You will need to import the following namespace.
Using TLS1.2 in .Net 2.0, .Net 3.0, .Net 3.5 and .Net 4.0
Inside the Page Load event, first the JSON string is downloaded from an API using DownloadString method of the WebClient class.
Note: In .Net 4.5 Framework project, you will get option for TLS 1.2 but in Net 2.0, .Net 3.0, .Net 3.5 and .Net 4.0, the value 3072 needs to be set in the SecurityProtocol as shown below.
Finally, the JSON string is written to the Response.
protected void Page_Load(object sender, EventArgs e)
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
string json = (new WebClient()).DownloadString("https://raw.githubusercontent.com/aspsnippets/test/master/Customers.json");
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")