连接到 UWP 中的 SignalR(核心)集线器时获取 "The certificate authority is invalid or incorrect"

Getting "The certificate authority is invalid or incorrect" when connecting to SignalR (Core) hub in UWP

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

在 .NET Core 应用程序 (2.1) 中它完美运行,而在 UWP 中它在调用 hub.StartAsync() 时抛出异常。

The certificate authority is invalid or incorrect

这是我的代码:

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

await hub.StartAsync();

这是怎么回事?

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

好的,我进入了 SignalR 的 Gitter Chat,一位好心的用户向我指出了修复方法。感谢他。这是对话的摘录。

Andrew Stanton-Nurse (@anurse): 您的应用程序使用 SSL 吗? URL 似乎是 http,但只有在使用自签名 SSL 证书时才会出现此错误

何塞·曼努埃尔·涅托@SuperJMN 我不确定!我使用的是默认 ASP。 NET Core 模板 Wep API。我怎样才能检查它?谢谢你的快速反应!

Andrew Stanton-Nurse @anurse 尝试在浏览器中导航到 URL,它会将您重定向到 https://localhost:...?

何塞·曼努埃尔·涅托@SuperJMN 好的,我在这里发现了问题

要使其正常工作,必须 取消选中

我知道这是前一段时间发布的。我遇到了同样的问题,并且像您一样未选中启用 SSL。是的,它可以工作,但如果您仍想保持 SSL 启用并针对 https 进行调试,您可以添加以下代码。 (仅用于调试,不要将其推送到任何产品中)。我还在 UWP

Package.appxmanifest 中启用了 Private Networks
    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;
        }

就我而言,我从 Package.appxmanifest

添加了以下功能