底层连接已关闭:无法建立 SSL/TLS 安全通道的信任关系
我有一段代码可以在 VS.C# 项目中运行,但是当该代码是 Sharepoint 中 webPart 的一部分时,它会引发错误。
ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;
HttpWebRequest httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(validateUrl);
HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
验证 url 是 HTTPS-uri。
在 Sharepoint 中,当我添加第一条规则时,当我转到页面并显示内容时,它会引发异常
未将对象引用设置为对象的实例。
我不确切知道它在哪里抛出此异常,因为这段代码被 Try { } Catch (Exception e) -块包围,但该代码没有被触发。所以这有点奇怪。
如果我放出第一条规则,它会抛出异常(在右侧的 catch 块中):
底层连接已关闭:无法建立 SSL/TLS 安全通道的信任关系。
如果我在 VS.C# 项目中给出第一条规则,这与我得到的异常相同。
有什么想法吗?或者其他解决方案?这显然不是最安全的方法。
I have a piece of code that works in a VS.C# project, but when this code is part of a webPart in Sharepoint, it throws an error.
ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;
HttpWebRequest httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(validateUrl);
HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
Validate url is a HTTPS-uri.
In Sharepoint, when I add the first rule it throws an exception when I go to the page and says
Object reference not set to instance of an object.
I do not exactly know where it throws this exception because this piece of code is being inclosed by a Try { } Catch (Exception e) -block, but that one isn't fired. So that's kind of weird.
If I let out the first rule, it throws an exception (in the right catch-block):
The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
Which is the same Exception I get if I let out the first rule in the VS.C# project.
Any ideas? Or other solutions? This is obviously not the safest approach.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过在“受信任的根证书颁发机构”存储中添加服务器证书(通过 MMC.exe),问题得到了解决,而无需接受所有证书。
By adding the server certificate in the "Trusted Root Certification Authorities" store (through MMC.exe) the problem was solved without the use of accepting all certificates.