無法 利用 授權 localhost 為 SSL TLS 安全通道建立信任關係

2019-07-07

C# HttpReques 基礎連接已關閉: 無法為 SSL/TLS 安全通道建立信任關係 強制跳過 TLS驗證

  • 7894
  • 0
  • C#
  • 2019-10-16

如提

C#  HttpReques 基礎連接已關閉: 無法為 SSL/TLS 安全通道建立信任關係    強制跳過 TLS驗證

參考來源

http://www.coco-in.net/thread-150342-1-1.html

https://blog.alantsai.net/posts/2017/12/csharp-ssl-remote-validation-error

可能會遇到這個畫面

無法 利用 授權 localhost 為 SSL TLS 安全通道建立信任關係

實際寫法

    ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

   HttpWebRequest request = HttpWebRequest.Create(targetUrl) as HttpWebRequest;
                request.Method = "GET";
            request.ContentType = "application/x-www-form-urlencoded";

            string jsondata = "";
            // 取得回應資料
            using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
            {
                using (StreamReader sr = new StreamReader(response.GetResponseStream()))
                {
                    jsondata = sr.ReadToEnd();
                }
            }

就可以解決了

以上文章僅用紀錄資料使用.....

2010-11-30

無法為 SSL/TLS 安全通道建立信任關係,忽略憑証檢查的方式

無法為 SSL/TLS 安全通道建立信任關係,忽略憑証檢查的方式

前言

在ASP.NET 2.0 WEB AP中去Call Https的Web Service時,如果會發生「WebException: 基礎連接已關閉: 無法為 SSL/TLS 安全通道建立信任關係。」,問了客戶IT後發現可以忽略憑証的檢查!

實作

用以上的Key Word到網路上找,可以找到一堆的解法! 可以寫在Page或是寫在Global.asax之中! 我選了個最Easy的方式,直接寫在Global.asax之中的Application_Start事件中寫入以下的Code,就可以了!


	void Application_Start(object sender, EventArgs e) 
{
    System.Net.ServicePointManager.ServerCertificateValidationCallback =
new System.Net.Security.RemoteCertificateValidationCallback(
    delegate(object MySender,
        System.Security.Cryptography.X509Certificates.X509Certificate MyCertificate,
        System.Security.Cryptography.X509Certificates.X509Chain MyChain,
        System.Net.Security.SslPolicyErrors MyErrors)
    {
        if (MySender is System.Net.WebRequest)
        {
            //忽略憑証檢查,一律回傳true
          return true;
        }
        return false;
    });
}
以上範例為網路上Copy來,並加以改寫的哦!

Hi, 

亂馬客Blog已移到了 「亂馬客​ : Re:從零開始的軟體開發生活

請大家繼續支持 ^_^

  • ServerCertificateValidationCallback
  • WebServices

您可能会收到消息:“升级 vCloud Automation Center 的安全证书时,无法为 SSL/TLS 安全通道建立信任关系 (Cannot establish trust relationship for the SSL/TLS secure channel when upgrading security certificates for vCloud Automation Center)。”

问题

如果升级安全证书时 vcac-config.exe 出现证书问题,您可能会看到以下消息:

基础连接已关闭: 无法为 SSL/TLS 安全通道建立信任关系 (The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel)

您可以使用以下过程找到问题原因的详细信息。

解决方案

  1. 在文本编辑器中打开 vcac-config.exe.config,找到存储库地址:

    <add key="repositoryAddress" value="https://IaaS-address:443/repository/" />

  2. 使用 Internet Explorer 访问该地址。
  3. 继续查看与证书信任问题相关的任何错误消息。
  4. 从 Internet Explorer 获取安全报告,并使用此报告对证书不受信任的原因进行故障排除。

解决方案

如果问题仍然存在,请通过浏览注册所需的地址(即:用于向 vcac-config.exe 进行注册的端点地址)重复此过程。

您可能會收到以下訊息:「升級 vCloud Automation Center 的安全性憑證時,無法為 SSL/TLS 安全通道建立信任關係。」

問題

如果升級安全性憑證時 vcac-config.exe 發生憑證問題,您可能會看到下列訊息:

基礎連線已關閉: 無法為 SSL/TLS 安全通道建立信任關係。

您可以使用下列程序,找到有關問題原因的更多資訊。

解決方案

  1. 在文字編輯器中開啟 vcac-config.exe.config,並找到存放庫位址:

    <add key="repositoryAddress" value="https://IaaS-address:443/repository/" />

  2. 開啟 Internet Explorer 以存取此位址。
  3. 透過有關憑證信任問題的任何錯誤訊息繼續。
  4. 從 Internet Explorer 取得安全性報告,並使用此報告疑難排解此憑證不受信任的原因。

解決方案

如果問題持續發生,請透過瀏覽需登錄的位址 (用於向 vcac-config.exe 登錄的端點位址),來重複此程序。