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

djh*_*man 3 .net iis tls1.2 .net-4.6.1

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

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

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

Tls, Tls11, Tls12
Run Code Online (Sandbox Code Playgroud)

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

Ssl3, Tls
Run Code Online (Sandbox Code Playgroud)

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

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

<compilation debug="true" targetFramework="4.6.1">
Run Code Online (Sandbox Code Playgroud)

但是,似乎IIS忽略了“ targetFramework”属性。

我需要在IIS中做些什么才能使其按预期工作?

更新:

看来IIS实际上是在使用“ targetFramework”属性,但是与控制台应用程序相比,ServicePointManager.SecurityProtocol在IIS下仍返回不同的默认值。

djh*_*man 5

好-我解决了。

要更改网站的目标框架,请右键单击它,单击“属性页面”,然后在“构建”页面上更改“目标框架”。

如果执行此操作,则in将在“ system.web”节点下的“ compilation”节点上更改“ targetFramework”属性:

<compilation targetFramework="4.6.1" />
Run Code Online (Sandbox Code Playgroud)

但这还不够-您还需要在“ system.web”节点下的“ httpRuntime”节点上更改“ targetFramework”属性:

<httpRuntime targetFramework="4.6.1" />
Run Code Online (Sandbox Code Playgroud)

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