简体   繁体   English

“以管理员身份运行”(System.Net.WebException:请求被中止:无法创建 SSL/TLS 安全通道。)

[英]"Run as Administrator" (System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.)

I am getting the WebException error only on 2 PCs (i tryed 5 diferent PCs).我只在 2 台 PC 上收到 WebException 错误(我尝试了 5 台不同的 PC)。 The problem does not occure if i start application "As administrator".如果我以“管理员身份”启动应用程序,则不会出现此问题。

I have tryed to add我已经尝试添加

ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;

and also change diferent flags for certificate并更改证书的不同标志

X509Certificate2 Cert = new X509Certificate2(fileName, "", X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet);

But it didn't help.但它没有帮助。

    try
    {
        string webLink = @"https://" + destinationIP + "/apps/MMC/";
        //get firmware version of trellisware radio
        string fileName = Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + "etc" + Path.DirectorySeparatorChar + "default.p12";
        X509Certificate2 Cert = new X509Certificate2(fileName, "", X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet);
        CertificateWebClient myWebClient = new CertificateWebClient(Cert);
        string webData = myWebClient.DownloadString(webLink);
        Uri responseUri = myWebClient.ResponseUri;

        string[] response = responseUri.ToString().Split('/');
    }
    catch (WebException ws) 
    { 
        logger.Error("WebException: " + webLink + Environment.NewLine + ws);
    }
    catch (SocketException) { }
    catch (ThreadAbortException) { }
    catch (Exception ex)
    {
        logger.Error("Exception: " + webLink + Environment.NewLine + ex);
    }

    public class CertificateWebClient : WebClient
    {
        private readonly X509Certificate2 certificate;

        public CertificateWebClient(X509Certificate2 cert)
        {
            certificate = cert;
        }

        protected override WebRequest GetWebRequest(Uri address)
        {
            HttpWebRequest request = (HttpWebRequest)base.GetWebRequest(address);

            System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate (Object obj, X509Certificate X509certificate, X509Chain chain, System.Net.Security.SslPolicyErrors errors)
            {
                return true;
            };

            request.ClientCertificates.Add(certificate);
            return request;
        }

        Uri _responseUri;

        public Uri ResponseUri
        {
            get { return _responseUri; }
        }

        protected override WebResponse GetWebResponse(WebRequest request)
        {
            WebResponse response = base.GetWebResponse(request);
            _responseUri = response.ResponseUri;
            return response;
        }
    }

Exceptions:例外:

2019-05-13 07:04:48.0050 | Error | OManager | WebException: https://169.1.28.23/apps/MMC/
System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.
   at System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request)
   at System.Net.WebClient.DownloadString(Uri address)
   at CAstralPilot.OcelotManager.<>c__DisplayClass26_0.<getGCSTrelliswareVersion>b__0() in 


2019-05-13 07:04:48.2081 | Warn | Genesys.Bayeux.Client | Request transport failed. Retrying after 00:00:00 Exception: 
Genesys.Bayeux.Client.BayeuxTransportException: Unable to connect to the remote server ---> System.Net.WebSockets.WebSocketException: Unable to connect to the remote server ---> System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.
   at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Net.WebSockets.ClientWebSocket.<ConnectAsyncCore>d__21.MoveNext()
   --- End of inner exception stack trace ---
   at System.Net.WebSockets.ClientWebSocket.<ConnectAsyncCore>d__21.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Genesys.Bayeux.Client.WebSocketTransport.<Open>d__12.MoveNext()
   --- End of inner exception stack trace ---
   at Genesys.Bayeux.Client.WebSocketTransport.<Open>d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Genesys.Bayeux.Client.ConnectLoop.<Poll>d__16.MoveNext()

I expected the code to work on al PCs, why some of them need administrator rights so WebClient can connect?我希望代码可以在所有 PC 上运行,为什么其中一些需要管理员权限才能连接 WebClient? Do i need to add certificate on some trusted location so it can work?我是否需要在某个受信任的位置添加证书才能正常工作?

解决方案是在管理用户证书(certmgr)和管理计算机证书(certlm)中添加证书

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 该请求已中止:无法创建SSL / TLS安全通道。 | System.Net.WebException - The request was aborted: Could not create SSL/TLS secure channel. | System.Net.WebException System.Net.WebException:请求已中止:无法创建SSL / TLS安全通道 - System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel 条纹支付:System.Net.WebException:请求被中止:无法创建 SSL/TLS 安全通道 - Stripe Payment: System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel WebException:请求已中止:无法创建SSL / TLS安全通道 - WebException: The request was aborted: Could not create SSL/TLS secure channel System.Net.HttpWebRequest.GetResponse()中的错误“ResponceSystem.Net.WebException:请求已中止:无法创建SSL / TLS安全通道” - Error in System.Net.HttpWebRequest.GetResponse() “ResponceSystem.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel” 使用 WebClient 时出现 System.Net.WebException:无法创建 SSL/TLS 安全通道 - System.Net.WebException when using WebClient: Can not create SSL/TLS secure channel 该请求已中止:无法创建SSL / TLS安全通道。 调用PostAsJsonAsync时 - The request was aborted: Could not create SSL/TLS secure channel. when calling PostAsJsonAsync HttpWebrequest 因 yande.re(以及 IE 和 curl)而失败[“请求已中止:无法创建 SSL/TLS 安全通道。”] - HttpWebrequest fails with yande.re (and IE and curl)["The request was aborted: Could not create SSL/TLS secure channel."] 该请求已中止:无法创建SSL / TLS安全通道。 用于HttpWebRequest和WebClient - The request was aborted: Could not create SSL/TLS secure channel. for HttpWebRequest and WebClient 请求被中止:无法创建 SSL/TLS 安全通道。 在本地工作但不住在 - The request was aborted: Could not create SSL/TLS secure channel. Working locally but not live
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM