Web request not going through with TLS 1.2 enabled in registry in C# application

Deepika 21 Reputation points
2020-12-16T12:53:35.62+00:00

I have a C# windows application and I am trying to make a web request on a URL using HttpWebRequest. I have enabled TLS 1.2 in the registry at below location

Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2

At the same time I have TLS 1.0 and TLS 1.1 disabled from the registry.

while I make call to the URL, it fails until and unless I add the below code in my solution System.Net.ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;

But I do not want to hardcode TLS value in my code.

What else could I do that would help solving this issue?

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,655 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jaliya Udagedara 2,821 Reputation points MVP
    2020-12-16T16:52:07.143+00:00

    Yes, you shouldn't be hard-coding a fixed set of protocols. But here what your code does is enabling Tls12 without affecting others which is fine. It automatically takes advantage of new protocols added in the future.

    Or you can target .NET Framework 4.7 or later versions on your apps. Target .NET Framework 4.7.1 or later versions on your WCF apps: Transport Layer Security (TLS) best practices with the .NET Framework


0 additional answers

Sort by: Most helpful