- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我对控制台应用程序如何连接到 Azure SignalR 服务器以接收通过 ASP.NET Core Web API 应用程序发送的通知感到有点困惑。
在启动我的 API 时,我会执行所需的操作:
services.AddSignalR().AddAzureSignalR();
app.UseAzureSignalR(routes =>
{
routes.MapHub<NotificationHub>("/notifications");
});
AddAzureSignalR() 方法通过我在应用程序设置中定义的连接字符串连接到 Azure SignalR 服务器。
但正如我在许多示例中看到的那样,要与我的控制台应用程序连接,我需要执行以下操作:
var connectionBuilder = new HubConnectionBuilder()
.WithUrl("http://localhost:5000/notifications")
.Build();
await connectionBuilder.StartAsync();
connectionBuilder.On<string, string>("broadcastNotification", (name, message) =>
{
Console.WriteLine($"Name: {name}, Message: {message}");
});
我的控制台应用程序通过 API 而不是直接连接到 Azure SignalR 服务器的原因是什么?安全还是有意为之?
最佳答案
What are the reasons that my console application connects to the Azure SignalR server through my API and not directly? Security or by design?
根据您的描述和代码,您似乎有一个 hub server并与 Azure SignalR 服务集成。
在这种类似于 this official example 的场景中如图所示,Azure SignalR 服务的服务模式将是默认模式。在此模式下,您的应用程序将作为典型的 ASP.NET Core(或 ASP.NET)SignalR 应用程序工作,并且客户端将需要中心服务器才能像您一样进行连接。
有关服务模式以及如何选择合适的服务模式的更多信息,请查看此文档:
关于.net - 控制台应用程序如何连接到 Azure SignalR 服务器以从我的 Web API 获取通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67489160/
我是一名优秀的程序员,十分优秀!