Why does adding httpRuntime targetFramework in Web.config file in a WCF application resolving TLS related connectivity issue?

时间:2018-09-18 19:58:18

标签: c# .net wcf ssl tls1.2

We have a few ASP.NET and WCF applications that are continuously being migrated to latest .net framework version as it is being released. This migration was working fine until we reached .NET Framework 4.6.2 and since then we started seeing TLS connectivity error like below. When I added <httpRuntime targetFramework="4.6.2" /> under <system.web> in the Web.config file, the error disappeared. So as I understand, this setting is forcing the application to run under .NET Framework 4.6.2 (without this, I believe the application was running under .NET Framework 4.0), which is causing it to use underlying Operating System's default protocol for securing the connection. Please correct my understanding if I am missing something.

System.AggregateException: One or more errors occurred. ---> System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult) at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult) --- End of inner exception stack trace --- at System.Net.TlsStream.EndWrite(IAsyncResult asyncResult) at System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar) --- End of inner exception stack trace --- at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar) --- End of inner exception stack trace ---

1 个答案:

答案 0 :(得分:2)

看看这个:https://blogs.perficient.com/2016/04/28/tsl-1-2-and-net-support。 NET 4.6及更高版本默认使用TLS 1.2,但默认不支持TLS 1.2,而4.0及更低版本则不支持TLS。

也许您的应用程序更新之一,IIS或OS配置更改已禁用<1.2的TLS版本,并且客户端应用程序无法连接。

关于设置<httpRuntime targetFramework="4.6.2" />,我们发现了同样的事情。仅更改项目文件中的目标框架和targetFramework元素中的compilation值是不够的。对于TLS,它仍然保留<.NET 4.6行为。实际上,在更改目标框架时,Visual Studio在注释掉的块中将httpRuntime元素添加到了web.config中。

(这里推荐的答案也有帮助:What do the TargetFramework settings mean in web.config in ASP .NET MVC?