我收到一个未处理的异常,显示 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/