无法通过在 web.config 中添加 appcontext 设置来将应用设置为使用系统默认 TLS 版本

ray*_*en3 6 network-programming .net-4.6 tls1.2

根据TLS 协议编程的.net 指南,当您的项目面向 .net 4.6 时,建议通过 appcontext 开关配置安全性。当在 app.config 中为控制台应用程序添加 appcontext 时,这种方式有效。但是,在网站项目的 web.config 中添加 appconext 开关时它不起作用。

这是我添加的配置。

<runtime>
   <AppContextSwitchOverrides value="Switch.System.Net.DontEnableSchUseStrongCrypto=false;Switch.System.Net.DontEnableSystemDefaultTlsVersions=false"/>
</runtime>
Run Code Online (Sandbox Code Playgroud)

ray*_*en3 16

AppContext 在 web 配置文件中切换用法:

<appSettings>
    <add key="AppContext.SetSwitch:Switch.System.Net.DontEnableSchUseStrongCrypto" value="false" />
    <add key="AppContext.SetSwitch:Switch.System.Net.DontEnableSystemDefaultTlsVersions" value="false" />
</appSettings>
Run Code Online (Sandbox Code Playgroud)

https://github.com/dotnet/docs/issues/6675

  • 虽然这有效,但设置 `&lt;httpRuntime targetFramework="4.7.2" /&gt;` 也可能有效。/sf/answers/3888746151/ (2认同)