- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我在 Windows 10 1903 上,我的 IE 和 Chrome 无需任何特殊设置即可访问 Tls 1.2 网站。但是当我尝试使用我的 .net 4.7.2 应用程序访问只允许 Tls 1.2 连接的 Web API 时,我的连接被服务器终止了。
我必须在我的代码中添加 ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;
以允许我的应用程序正确连接到该端点。
但经过一些研究,我发现来自 this记录 .Net 4.7 及更高版本的 ServicePointManager.SecurityProtocol
的默认值应为 SecurityProtocolType.SystemDefault
并根据 this记录默认情况下启用 Tls 1.2 协议(protocol)。
所以我跟踪我的代码,发现我系统上 ServicePointManager.SecurityProtocol
的默认值是 System.Net.SecurityProtocolType.Ssl3 | System.Net.SecurityProtocolType.Tls
。更疯狂的是,当我将协议(protocol)设置为 SecurityProtocolType.SystemDefault
时,我得到了这个错误:
System.Net.Http.HttpRequestException : An error occurred while sending the request.
---- System.Net.WebException : The underlying connection was closed: An unexpected error occurred on a receive.
-------- System.ArgumentException : The specified value is not valid in the 'SslProtocolType' enumeration.
Parameter name: sslProtocolType
我检查了我的系统 registry和 IE 设置,并且没有任何内容会覆盖或禁用 Tls 1.2。
所以我很困惑,想知道是不是我的系统或我的代码有问题。
最佳答案
如果您正在运行的应用程序目标早于 4.6 的 .NET 框架(即使您实际上是在较新的 .NET FX 上运行它),您将收到此错误。您可以通过检查 AppDomain.CurrentDomain.SetupInformation.TargetFrameworkName
的值来检查这一点。
具体来说,这将在 SystemDefaultTlsVersions 的情况下被抛出注册表值未设置为 1
: https://referencesource.microsoft.com/#System/net/System/Net/SecureProtocols/_SslState.cs,164
AppContext switches也不会帮助你,因为它们只对从 4.6 开始的框架版本生效。假设您不能更改目标 .NET 版本 ( example ) 并且您不想强制您的用户更改他们的注册表设置,我推荐这样的代码:
if (ServicePointManager.SecurityProtocol != SecurityProtocolType.SystemDefault)
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
}
更多信息: https://learn.microsoft.com/en-us/dotnet/framework/network-programming/tls
关于c# - ServicePointManager.SecurityProtocol 不是 SecurityProtocolType.SystemDefault,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57879579/
我想知道当我在她的标志上设置三个不同的 SecurityProtocolType 时属性 ServicePointManager.SecurityProtocol 是如何工作的。即: ServiceP
在 .NET 4.5 中,如果我将 ServicePointManager.SecurityProtocol 设置为多个协议(protocol)并且服务器接受所有这些协议(protocol),将使用哪
目前我有一个问题,找不到严格的答案。 我有针对 4.6.1 框架的 ASP.NET MVC 5 应用程序,它的目标是使用受 TLS 1.1/TLS 1.2 协议(protocol)保护的第三方 API
这个问题在这里已经有了答案: Set the SecurityProtocol (Ssl3 or TLS) on the .net HttpWebRequest per request (11 个答
我在 Windows 10 1903 上,我的 IE 和 Chrome 无需任何特殊设置即可访问 Tls 1.2 网站。但是当我尝试使用我的 .net 4.7.2 应用程序访问只允许 Tls 1.2
我的生产代码工作正常,但我的集成测试抛出 SecurityProtocol 的 ClassNotFoundException。我正在使用 spring-boot-parent 1.5.10.RELEA
我正在尝试将一组项目更新到 .NET 4.6.1 以获得 TLS 1.2 支持。该解决方案包含类库、控制台应用程序、WebForms 网站和 MVC 网站的组合。 我已经将每个项目和网站更改为以 .N
我想支持从 ssl3 到 tls 1.2 的所有安全协议(protocol)。但是在网上搜索时,我发现代码为 `ServicePointManager.SecurityProtocol = Secur
.NET 5 对 TLS 进行了重大更改。所以当我连接到一个网站(通过 HttpClient )并且它不支持 TLS 1.3(这是 .NET5 的默认值)时,我收到以下错误:Interop+Crypt
我有一个发送传出请求的 WCF 服务。目前它使用 SSL 3.0 或 TLS 1.0。 我发送请求的服务现在只接受 TLS 1.2。 我可以在请求之前(以及每个请求)设置 SecurityProtoc
在 .NET 4.0 和 4.5 中,根据 this,ServicePointManager.SecurityProtocol 的默认值为 SecurityProtocolType.Tls|Secur
我的应用程序(.net 3.5 sp1)使用 HttpWebRequest 与不同的端点进行通信,有时它通过 HTTPS 进行通信,其中每个托管服务器可能有不同的安全协议(protocol)要求,例如
将证书安装到受信任的根证书颁发机构 的本地计算机 存储后,.NET WebRequest 仍然会抛出: The request was aborted: Could not create SSL/TL
我需要升级 .NET 应用程序以支持在仅支持 TLS 1.2 的网站上调用 API。据我了解,如果应用程序的目标是 4.6 或更高版本,那么它将默认使用 TLS 1.2。 为了测试,我创建了一个面向
我是一名优秀的程序员,十分优秀!