我有一段代码可以在 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 中,当我添加第一条规则时,它会在我转到页面时抛出异常
Object reference not set to instance of an object.
我不完全知道它在哪里抛出这个异常,因为这段代码被 Try { } Catch (Exception e) block 包围,但是那个代码没有被触发。所以这有点奇怪。
如果我放出第一个规则,它会抛出一个异常(在右边的 catch block 中):
The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
如果我放弃 VS.C# 项目中的第一条规则,这与我得到的异常相同。
有什么想法吗?还是其他解决方案?这显然不是最安全的方法。
最佳答案
通过在“受信任的根证书颁发机构”存储中添加服务器证书(通过 MMC.exe),无需接受所有证书即可解决问题。
关于sharepoint - 底层连接已关闭 : Could not establish trust relationship for the SSL/TLS secure channel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3636405/