Goo*_*k12 6 c# signalr.client asp.net-core
我正在制作一个应用程序,它涉及本地主机上的网站,作为带有 Asp.net Core 和 SignalR Core 的用户界面。
我的问题是在启动连接时出现身份验证异常。我知道这是因为我没有跑dotnet dev-certs https --trust。但我不能指望普通用户运行此命令或安装 dotnet SDK。
我试过使用
ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;
Run Code Online (Sandbox Code Playgroud)
在我的 Startup.cs(和其他地方,但我知道这是一个全局设置。无论如何它是在 HubConnection 之前执行的)无济于事。我也尝试设置一个新的 HttpMessageHandlerFactory,但文档告诉我这不会影响 Websockets。
我不相信这是一个解决方案,因为我不能使用不同的 HttpClient(除非我弄错了)
如您所见,我根本没有连接到 https:
connection = new HubConnectionBuilder().WithUrl("http://localhost:5000/MiniLyokoHub" ).Build();
Run Code Online (Sandbox Code Playgroud)
所以我不明白为什么它甚至试图获得证书。
这是完整的错误:https : //pastebin.com/1ELbeWtc
我怎样才能解决这个问题?我不需要证书,因为用户将连接到他们自己的本地主机。还是我不应该使用 websockets?
Mah*_*ahi 10
连接到 HTTPS 时,要始终验证 SignalR Core 客户端中的 SSL 证书,您应该在HttpMessageHandlerFactory配置中执行此操作。HttpConnectionOptions在这样的WithUrl方法中使用:
connection = new HubConnectionBuilder()
.WithUrl("https://localhost:443/MiniLyokoHub", (opts) =>
{
opts.HttpMessageHandlerFactory = (message) =>
{
if (message is HttpClientHandler clientHandler)
// always verify the SSL certificate
clientHandler.ServerCertificateCustomValidationCallback +=
(sender, certificate, chain, sslPolicyErrors) => { return true; };
return message;
};
})
.Build();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4630 次 |
| 最近记录: |