c# - .NET v4.7 中不存在 TLS1.2

标签 c# .net visual-studio tls1.2

我收到一个未处理的异常,显示 The request was aborted: could not create SSL/TLS secure channel所以我尝试使用 Tls1.2 希望它能解决这个问题。

我了解到 .NET 版本 4.6 及更高版本的默认设置是 TLS1.2

我有版本 4.7 并且有行 ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;在我的代码中,但.Tls12下有一个红色的linder 。 Visual Studio 说 SecurityProtocolTypes does not contain a definition for Tls12并建议我更换 .Tls12.Tls

如何在我的代码中使用 Tls1.2?

我应该补充一点,我也尝试过: ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;ServicePointManager.SecurityProtocol = (SecurityProtocolType)(0xc0|0x300 0xc00);

最佳答案

你读过Transport Layer Security (TLS) best practices with the .NET Framework吗? ?

它说:

To ensure .NET Framework applications remain secure, the TLS version should not be hardcoded.

.NET Framework applications should use the TLS version the operating system (OS) supports.

之后:

If your app targets .NET Framework 4.7 or later versions

The following sections show how to verify you're not using a specific TLS or SSL version.

For HTTP networking

ServicePointManager, using .NET Framework 4.7 and later versions, defaults to the OS choosing the best security protocol and version. To get the default OS best choice, if possible, don't set a value for the SecurityProtocol property. Otherwise, set it to SystemDefault.

如果默认情况下它不起作用...也许您并没有真正使用 4.7?

或者也许您的操作系统太旧了,不支持它?

或者目标可能不支持它?

无论哪种方式,都不需要显式地将其设置为 1.2

关于c# - .NET v4.7 中不存在 TLS1.2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57293244/

相关文章:

visual-studio - Xamarin Sport 应用程序 - 未知标识符

c# - 选择角色提供者 - ASP.net 成员(member)提供者

c# - 如何使用 .NET 检测 Windows 64 位平台?

c# - 模棱两可的引用意见

.net - SQL Server 通过集成登录提升权限

c# - 如何在C#上获取字符串的中心部分

.net - F# 类型的组合。如何实例化和使用。

c# - 对于循环读取文件不起作用

visual-studio - Visual Studio 2017 - 无法安装

asp.net-mvc - 当我在 Visual Studio 2013 中正在运行的另一个项目上打开一个项目时会发生什么?