c# - 如何使用 C# 勾选“TLS 1.2”(Internet 选项> 高级设置> 安全> TLS 1.2)
问题描述
我们的应用程序使用Webbrowser 控件/Internet Explorer 来显示一些网页。我们需要启用 TLS 1.2(Internet 选项->高级->安全->使用 TLS 1.2)来显示这些网页。现在,当禁用(默认禁用)TLS 1.2 选项时,我们在 Win 8 中面临一些问题。所以我们需要检查它是否被勾选,如果没有,我们需要在 C# 中以编程方式勾选它。我们已经尝试通过设置注册表值,但它没有帮助。有没有办法以编程方式勾选“Internet 选项->高级->安全->使用 TLS 1.2”。
解决方案
您可以使用Registry.SetValue 方法来设置更改注册表并启用 TLS 1.2。
代码如下(需要添加“using Microsoft.Win32;”引用):
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();
}
有关注册表项值的更多详细信息,请参阅本文。
推荐阅读
- javascript - TypeError:无法读取未定义的属性 / TypeError:无法将未定义或 null 转换为对象
- python - 为什么实例可以引用尚未在类函数中声明的属性
- kubernetes - 由于 Istio VirtualService,有没有办法代理对 ExternalName 服务的调用?
- c# - 使用客户端应用程序(html 和 js)中的公钥加密纯文本,并使用 ASP.NET Web API 中的私钥解密加密数据
- jsf - p:commandButton 可以在 p:rowExpansion 中使用吗?
- android - 我正在尝试使用 Jobscheduler 在 android 应用程序中删除图库中的图片,但我无法删除它们
- java - 自类型 - 需要类型绑定内的类型
- r - 在R中将数据从宽格式转换为长格式?
- python - python - 安装 dlib/face_recognition 时出现 VS 代码错误
- sql - 如何在使用聚合函数时修复 SQL 错误 SAP HANA