I'm trying to connect to a SignalR Core hub from my UWP application.
In a .NET Core application (2.1) it works perfectly, whereas in UWP it throws an exception when hub.StartAsync()
is called.
The certificate authority is invalid or incorrect
This is my code:
hub = new HubConnectionBuilder()
.WithUrl("http://localhost:49791/hubs/status")
.Build();
await hub.StartAsync();
What's going on?
I set guess I have to configure something in the Package Manifest, but what?
In My case, I added below capabilities from Package.appxmanifest
OK, I got into SignalR's Gitter Chat and one kind user has pointed me out the fix. Kudos to him. Here is the excerpt of the conversation.
Andrew Stanton-Nurse (@anurse): Is your application using SSL? The URL seems to be http but this error should only occur when using a self-signed SSL certificate
José Manuel Nieto @SuperJMN I'm not sure! I'm using the default ASP. NET Core template for Wep API. How can I check it? Thank you for the quick response! 😃
Andrew Stanton-Nurse @anurse try just navigating to the URL in a browser, does it redirect you to https://localhost:...?
José Manuel Nieto @SuperJMN OK, I discovered the problem here 👇
For it to work, this has to be unchecked 😃
I know this was posted some time ago. I had same issue and unchecked Enable SSL as you did. And yes it works, but if you want to still keep the SSL enable and debug against https, you can add the below code. (For Debugging only, do not push this into any production). I also enabled Private Networks
in the Package.appxmanifest
of UWP
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With