微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

需要在服务器环境中启用 TLS1.2 并禁用 TLS1.0 & 1.1

如何解决需要在服务器环境中启用 TLS1.2 并禁用 TLS1.0 & 1.1

我们在服务器中禁用了 TLS1.0 和 1.1,仅启用了 TLS1.2。但是我们收到了以下异常。

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.Receive(Byte[] buffer,Int32 offset,Int32 size,SocketFlags socketFlags)
   at System.Net.sockets.NetworkStream.Read(Byte[] buffer,Int32 size)
   --- End of inner exception stack trace ---
   at System.Net.sockets.NetworkStream.Read(Byte[] buffer,Int32 size)
   at System.Net.FixedSizeReader.ReadPacket(Byte[] buffer,Int32 count)
   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer,AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message,AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartSendBlob(Byte[] incoming,Int32 count,AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst,Byte[] buffer,AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
   at System.Net.Tlsstream.CallProcessAuthentication(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext,ContextCallback callback,Object state,Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext,Object state)
   at System.Net.Tlsstream.ProcessAuthentication(LazyAsyncResult result)
   at System.Net.Tlsstream.Write(Byte[] buffer,Int32 size)
   at System.Net.PooledStream.Write(Byte[] buffer,Int32 size)
   at System.Net.ConnectStream.WriteHeaders(Boolean async)
   --- End of inner exception stack trace ---
   at System.Net.HttpWebRequest.GetResponse()

我们尝试了以下解决方案。

  1. The underlying connection was closed: An unexpected error occured on a send

.Net 框架版本为 4.6.2。 有什么解决办法吗?

解决方法

只需放在应用程序的启动中即可:

  System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12 ;
      

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。