【问题标题】:TLS 1.2 .net 4.6.2 projectTLS 1.2 .net 4.6.2 项目
【发布时间】:2019-08-08 07:42:08
【问题描述】:

在 Global.asax(MVC5 项目)的 Appliction_Start 方法中,我有这行代码应该使用 TLS1.2

    if (ServicePointManager.SecurityProtocol.HasFlag(SecurityProtocolType.Tls12) == false)
            {
                ServicePointManager.SecurityProtocol = ServicePointManager.SecurityProtocol | SecurityProtocolType.Tls12;
            }

检查值

ServicePointManager.SecurityProtocol

在运行时显示这个值

System.Net.SecurityProtocolType.Ssl3 | System.Net.SecurityProtocolType.Tls | System.Net.SecurityProtocolType.Tls12

所以我假设正在使用 TLS1.2,但 Firefox 在控制台窗口中显示此消息

'此站点使用了已弃用的 TLS 版本,该版本将在 2020 年 3 月。请升级到 TLS 1.2 或 1.3'

如何确保使用 TLS 1.2?我正在使用 .net 框架 4.6.2

【问题讨论】:

    标签: c# visual-studio tls1.2


    【解决方案1】:

    在这一行:

    ServicePointManager.SecurityProtocol = ServicePointManager.SecurityProtocol | SecurityProtocolType.Tls12;
    

    您正在添加 Tls12 到支持的协议。在握手期间,根据客户端的能力选择这些支持的协议之一。要支持仅 Tls12,您可以使用:

    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
    

    【讨论】:

      【解决方案2】:

      .NET 4.6.2 应该默认使用 TLS 1.2。根本不需要您拥有的代码。 我的猜测是您可能使用了不同的 httpRuntime 版本,这会导致问题。

      尝试从您的Global.asax 中删除代码并在您的web.config 中明确设置httpRuntime 版本:

      <system.web>
        <httpRuntime targetFramework="4.6.2" />
      </system.web>
      

      【讨论】:

      • 我已将项目设置为 4.6.2 但 web.config 说 4.5.1
      • 我将 web.config 更改为 4.6.2 并在 global.asax 中将安全协议设置为 Tls12,但在 firefox 中仍然出现相同的错误
      【解决方案3】:

      我想通了,问题出在 IIS express 上。在本地运行站点并打开控制台窗口给了我 TLS 错误消息,但是当我运行部署在 Azure 中的站点时,我不再收到错误消息,所以一定是因为我是通过 IIS express 在本地运行它

      【讨论】:

        猜你喜欢
        • 2018-05-01
        • 1970-01-01
        • 2017-08-31
        • 2018-10-31
        • 2016-04-27
        • 2016-09-13
        • 2017-10-07
        • 1970-01-01
        • 2018-11-10
        相关资源
        最近更新 更多