Search code examples
c#.netwebbrowser-controlinternet-explorer-10tls1.2

How to tick "TLS 1.2"(Internet Option > Advanced setting > Security> TLS 1.2) using C#


Our application using Webbrowser control / Internet Explorer to display some web pages. We need to enable TLS 1.2(Internet Options->Advanced->Security->Use TLS 1.2) to display these web pages. Now we are facing some issues in Win 8 when disabling (by default disabled) TLS 1.2 option. So we need to check whether it is ticked and if not we need to tick it programmatically in C#. We have tried by setting registry value but it doesn’t’ help. Is there any way to tick "Internet Options->Advanced->Security->Use TLS 1.2" programmatically.


Solution

  • You could use the Registry.SetValue Method to set change the registry and enable TLS 1.2.

    Code as below (need to add the "using Microsoft.Win32;" reference):

    static void Main(string[] args)
    {
        // The name of the key must include a valid root.
        const string userRoot = @"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings";
        const string subkey = "SecureProtocols";
    
        //get the registry value.
        string result = (Registry.GetValue(userRoot, subkey, "Return this default if NoSuchName does not exist")).ToString();
        Console.WriteLine(result);
    
        //Enable TLS 1.0 and TLS 1.2 
        Registry.SetValue(userRoot, subkey, 2176);
    
        Console.WriteLine("OK");
        Console.ReadKey();
    }
    

    More details about the registry key value, please refer to this article.