代码之家  ›  专栏  ›  技术社区  ›  SuperJMN

在UWP中连接到信号器(核心)集线器时获取“证书颁发机构无效或不正确”

  •  0
  • SuperJMN  · 技术社区  · 6 年前

    我正在尝试从我的UWP应用程序连接到SignalR核心集线器。

    hub.StartAsync() 被称为。

    证书颁发机构无效或不正确

    这是我的密码:

    hub = new HubConnectionBuilder()
        .WithUrl("http://localhost:49791/hubs/status")
        .Build();
    
    await hub.StartAsync();
    

    我想我必须在包清单中配置一些东西,但是什么?

    2 回复  |  直到 6 年前
        1
  •  5
  •   SuperJMN    6 年前

    好吧,我进入了signaler的Gitter聊天,一个好心的用户给我指出了解决方法。他真是太好了。这是谈话的摘录。

    安德鲁·斯坦顿护士(@anurse): 您的应用程序是否使用SSL?URL似乎是http,但此错误只应在使用自签名SSL证书时发生

    安德鲁·斯坦顿护士@anurse https://localhost :...?

    好吧,我在这里发现了问题

    Snapshop

    为了让它工作,这是必须的 未检查

        2
  •  3
  •   Laurent Greyling    5 年前

    我知道这是前段时间贴的。我和你有同样的问题和问题。是的,它可以工作,但是如果您仍然想保持SSL的启用和对https的调试,您可以添加下面的代码(仅用于调试,请勿将其推入任何生产环境)。我还启用了 Private Networks Package.appxmanifest

        Connection = new HubConnectionBuilder().WithUrl("https://localhost:44333/clienthub", options =>
                        {
                            options.HttpMessageHandlerFactory = (handler) =>
                            {
                                if (handler is HttpClientHandler clientHandler)
                                {
                                    clientHandler.ServerCertificateCustomValidationCallback = ValidateCertificate;
                                }
                                return handler;
                            };
                        }).Build();
    
    bool ValidateCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
            {
                // TODO: You can do custom validation here, or just return true to always accept the certificate.
                // DO NOT use custom validation logic in a production application as it is insecure.
                return true;
            }
    
        3
  •  2
  •   Ankit    4 年前

    在我的例子中,我从Package.appxmanifest添加了以下功能

    enter image description here