首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ServicePointManager SecurityProtocol冲突

ServicePointManager SecurityProtocol冲突
EN

Stack Overflow用户
提问于 2015-11-10 22:19:31
回答 1查看 2.6K关注 0票数 10

在我的应用程序中,我使用RestSharp查询REST和System.Net.Mail来发送电子邮件。在程序启动时,我设置了ServicePointManager.SecurityProtocol属性。

如果我将属性设置为:

代码语言:javascript
复制
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11;

使用RestSharp查询API时引发异常:

代码语言:javascript
复制
The request was aborted: Could not create SSL/TLS secure channel

如果我将属性设置为:

代码语言:javascript
复制
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls11;

在用System.Net.Mail发送电子邮件时引发异常:

代码语言:javascript
复制
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

我该如何解决这个问题呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-11-12 23:53:21

您所连接的REST服务器和邮件服务器显然具有冲突的安全协议要求。您需要为它们使用不同的安全协议设置。

ServicePointManager.SecurityProtocol是静态的,其当前值适用于所有新连接。不幸的是,没有办法控制每个ServicePoint的这个设置。(在我看来,这是微软的一个设计缺陷)

如果您控制了REST服务器或邮件服务器,那么您也许可以重新配置它们以接受不冲突的安全协议。

否则,您可以重新设计代码,以便所有到REST和邮件服务器的连接都由两个单独的AppDomains组成。

例如,让默认的应用程序域处理所有REST通信,并生成一个单独的应用程序域来完成所有邮件通信。

使用此设置,您可以在每个域中使用不同的ServicePointManager.SecurityProtocol值。(因为静态值在应用程序域之间不共享)。

票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33640752

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档