在我的应用程序中,我使用RestSharp查询REST和System.Net.Mail来发送电子邮件。在程序启动时,我设置了ServicePointManager.SecurityProtocol属性。
如果我将属性设置为:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11;使用RestSharp查询API时引发异常:
The request was aborted: Could not create SSL/TLS secure channel如果我将属性设置为:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls11;在用System.Net.Mail发送电子邮件时引发异常:
System.Security.Authentication.AuthenticationException: A call to SSPI failed, see inner exception. ---> System.ComponentModel.Win32Exception: The client and server cannot communicate, because they do not possess a common algorithm我该如何解决这个问题呢?
发布于 2015-11-12 23:53:21
您所连接的REST服务器和邮件服务器显然具有冲突的安全协议要求。您需要为它们使用不同的安全协议设置。
ServicePointManager.SecurityProtocol是静态的,其当前值适用于所有新连接。不幸的是,没有办法控制每个ServicePoint的这个设置。(在我看来,这是微软的一个设计缺陷)
如果您控制了REST服务器或邮件服务器,那么您也许可以重新配置它们以接受不冲突的安全协议。
否则,您可以重新设计代码,以便所有到REST和邮件服务器的连接都由两个单独的AppDomains组成。
例如,让默认的应用程序域处理所有REST通信,并生成一个单独的应用程序域来完成所有邮件通信。
使用此设置,您可以在每个域中使用不同的ServicePointManager.SecurityProtocol值。(因为静态值在应用程序域之间不共享)。
https://stackoverflow.com/questions/33640752
复制相似问题