为什么 ServicePointManager.SecurityProtocol 在同一台机器上的控制台应用程序和 IIS 网站不同?

Why is ServicePointManager.SecurityProtocol different in console application and IIS website on the same machine?

我正在尝试将一组项目更新到 .NET 4.6.1 以获得 TLS 1.2 支持。该解决方案包含 class 库、控制台应用程序、WebForms 网站和 MVC 网站的组合。

我已经将每个项目和网站更改为以 .NET 4.6.1 为目标,并重新编译所有内容。

现在,如果我在其中一个控制台应用程序中检查 ServicePointManager.SecurityProtocol 的默认值,则会得到以下信息:

Tls, Tls11, Tls12

但是,如果我在 IIS 下的 WebForms 网站之一 运行 中检查 ServicePointManager.SecurityProtocol 的默认值,则会得到以下信息:

Ssl3, Tls

因此,在 IIS 下比较控制台应用程序和 WebForms 网站时,我可以在同一台机器上看到 ServicePointManager.SecurityProtocol 的不同值。

我可以确认 WebForms 网站在 "system.web" 下的 Web.config 中有以下内容:

<compilation debug="true" targetFramework="4.6.1">

但似乎 IIS 忽略了 "targetFramework" 属性。

我需要在 IIS 中做些什么才能让它按预期工作吗?

更新:

看来 IIS 实际上遵循 "targetFramework" 属性,但 ServicePointManager.SecurityProtocol 与控制台应用程序相比,IIS 下的默认值仍然 returns 不同。

好的 - 我解决了。

要更改网站的目标框架,请右键单击它,单击 "Property Pages",然后在 "Build" 页面上更改 "Target Framework"。

如果这样做,那么将更改 "system.web" 节点下的 "compilation" 节点上的 "targetFramework" 属性:

<compilation targetFramework="4.6.1" />

但这还不够——您还需要更改 "system.web" 节点下的 "httpRuntime" 节点上的 "targetFramework" 属性:

<httpRuntime targetFramework="4.6.1" />

现在,IIS 下的网站和控制台应用程序都报告了 ServicePointManager.SecurityProtocol 的相同内容。