我是否需要在我的 ASP .NET 4.6 应用程序中强制使用 TLS 1.2?

Do I need to force the use of TLS 1.2 in my ASP .NET 4.6 application?

我们有第三方 API 不久将强制使用 TLS 1.2。

我们有两个单独的应用程序连接到此 API,一个控制台应用程序和一个 ASP.NET Web 应用程序,它们都是用 C# 编写的。

我已将控制台应用程序重新定位为使用也安装在主机上的 .NET 4.6。我在 Main.

的顶部添加了这个
private static void Main(string[] args)
{
    // Enable TLS 1.2
    ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;

   // Disable old protocols
   ServicePointManager.SecurityProtocol &= ~(SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11);

    ...

}

我相信这对于控制台应用程序来说已经足够了,因为它只有一个入口点。

但是,我对 ASP.NET Web 应用程序需要做什么感到困惑。

首先它由 3 个项目组成。两个分别是框架层和服务层的 class 库,第三个是 UI 的 ASP Web 应用程序。我已经完成了其中的每一项,并将它们定位为 .NET 4.6。
从我读到的内容来看,这听起来像是我需要做的所有事情,因为默认情况下将协商最高协议。

我说得对吗?

如果我错了,我应该在哪里添加来自控制台应用程序的同一行? Global.asax?

由于 ServicePointManager.SecurityProtocolstatic,您只需为每个应用程序配置一次。这意味着将该代码放入 Application_Start 事件中就足够了。