The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel

。_饼干妹妹 提交于 2019-12-12 01:35:38

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/3636405/the-underlying-connection-was-closed-could-not-establish-trust-relationship-for

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!