[英]Issues making a TLS 1.2 request with .NET Framework 4.7+
We have a .NET 4.7+ application running on an Azure Cloud App Service.我们有一个在 Azure 云应用服务上运行的 .NET 4.7+ 应用程序。 When we try to call and API that has TLS 1.2 minimum, using HttpWebRequest, we get a "The request was aborted: Could not create SSL/TLS secure channel" error.
当我们尝试使用 HttpWebRequest 调用最低 TLS 1.2 的 API 时,我们收到“请求中止:无法创建 SSL/TLS 安全通道”错误。 What I have read so far:
到目前为止我读过的内容:
ServicePointManager.SecurityProtocol
, so I'm trying to avoid that solution unless it's absolutely necessary. ServicePointManager.SecurityProtocol
进行硬编码,因此除非绝对必要,否则我会尽量避免使用该解决方案。 Microsoft's guide What can be causing my app to be using a lower TLS version?什么可能导致我的应用使用较低的 TLS 版本? I have searched the code and could not find a manual TLS configuration anywhere.
我已经搜索了代码,但在任何地方都找不到手动 TLS 配置。 Is setting
ServicePointManager.SecurityProtocol
really my only solution?设置
ServicePointManager.SecurityProtocol
真的是我唯一的解决方案吗?
Add This In your code:在你的代码中添加这个:
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12
OR或者
If you have executable file simply update the associated configuration file, this file always named as [name of the executable].exe.config.如果您有可执行文件,只需更新关联的配置文件,此文件始终命名为[可执行文件的名称].exe.config。 If there's no such file, create one.
如果没有这样的文件,请创建一个。
Once located or created, update its content to enable the compatibility switch required to support TLS 1.2:找到或创建后,更新其内容以启用支持 TLS 1.2 所需的兼容性开关:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<runtime>
<AppContextSwitchOverrides value="Switch.System.Net.DontEnableSystemDefaultTlsVersions=false"/>
</runtime>
</configuration>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.