底层连接已关闭:无法建立 SSL/TLS 安全通道的信任关系

发布于 2024-09-17 18:17:16 字数 790 浏览 8 评论 0原文

我有一段代码可以在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陌上青苔 2024-09-24 18:17:16

通过在“受信任的根证书颁发机构”存储中添加服务器证书(通过 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文