Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

.NET 4.5 doesn't automatically use TLS 1.2  #3

@ronc90

Description

@ronc90

With Freightview's hosting platform now requiring TLS1.2, the FV C# sample API integration doesn't work without forcing
the connection to use TLS1.2.

Long-term solution: update code to use a more modern version of .net framework.

Short-term fix: force TLS1.2

add this line:

System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

in ApiClient.cs, like this:

public class ApiClient
	{
		public List<MediaTypeFormatter> formatters { get; private set; }
		public ApiClient(HttpClient apiClient)
		{
			this.Client = apiClient;
			this.formatters = new List<MediaTypeFormatter>();
			this.formatters.Add(new JsonMediaTypeFormatter() {SerializerSettings = new Newtonsoft.Json.JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore}});
			this.formatters.Add(new XmlMediaTypeFormatter());
                        System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; //this line added to force TLS1.2
		}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions