c# - 为什么 ServicePointManager.SecurityProtocol 默认值在不同机器上不同?

标签 c# .net asp.net-mvc ssl iis

目前我有一个问题,找不到严格的答案。

我有针对 4.6.1 框架的 ASP.NET MVC 5 应用程序,它的目标是使用受 TLS 1.1/TLS 1.2 协议(protocol)保护的第三方 API。

我尝试在 2 个环境中运行我的应用程序:

  • 我的本地计算机 Windows 10,带有 .NET 4.6.2 Framework,IIS Express;
  • 服务器计算机 Windows Server 2012,带 .NET 4.6.1、IIS 8.0;

问题在于,当我在本地启动它时 ServicePointManager.SecurityProtocol 默认值设置为 Ssl3, Tls,所以我无法定位 API,必须编写代码它在应用程序上开始使用 TLS 1.1/TLS 1.2:ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12.

当应用程序在服务器上运行时,默认值 ServicePointManager.SecurityProtocol 设置为 Tls, Tls11, Tls12,因此它运行良好。

根据文档,在 .NET Framework 4.6 或更高版本上运行的应用程序默认情况下必须使用 TLS 1.1/TLS 1.2,这是如何在远程计算机上实现的。

为什么 ServicePointManager.SecurityProtocol 的默认值不同?是因为 .NET Framework 配置吗?或者注册表设置?我已经搜索过了,但找不到答案。

最佳答案

MSDN: ServicePointManager.SecurityProtocol Property :

Note that no default value is listed for this property, on purpose. The security landscape changes constantly, and default protocols and protection levels are changed over time in order to avoid known weaknesses. Defaults will vary depending on individual machine configuration, and on which software is installed, and on which patches have been applied.

MSDN Blogs: Support for SSL/TLS protocols on Windows :

On Windows the support for SSL/TLS protocols is tied to the SCHANNEL component. So, if a specific OS version doesn’t support a SSL/TLS version, this means it remains unsupported.

MSDN: Cipher Suites in TLS/SSL (Schannel SSP)

Different Windows versions support different TLS cipher suites and priority order. See the corresponding Windows version for the default order in which they are chosen by the Microsoft Schannel Provider.

换句话说:这取决于您的 Windows 版本及其补丁级别。

但正如@Damien 所说,您为什么要关心默认级别是多少?

关于c# - 为什么 ServicePointManager.SecurityProtocol 默认值在不同机器上不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39246999/

相关文章:

c# - Count Query generation in table-per-type inheritance

c# - Culture 是否自动应用于 ASP.Net Webforms? (不是 UICulture)

c# - 动态创建 <Type> 的对象

c# - 无法在 EF Where 表达式中使用 LINQ 用于 lambda 属性

.net - 使用 Mono 发送 Windows 消息

c# - 在单个桌面应用程序中管理 40 个 SQL 连接

c# - 谷歌身份验证 OWIN ASP.NET

asp.net - 使用另一种身份验证方法进行外部 api 调用

c# - 如何将 double 值转换为时间? C#/ASP.NET

c# - ASP.NET 无法使用 FtpWebRequest 类启用 SSL 而不会出现错误