简体   繁体   English

在基本路径中使用 BlazorHub 的 Blazor-Server 通知?

[英]Blazor-Server Notifications with BlazorHub in base path?

I'm trying to make the client side receive notifications in realtime using BlazorHub.我试图让客户端使用 BlazorHub 实时接收通知。 In all the example that I have found, a hub gets mapped to it's own path like在我找到的所有示例中,集线器都被映射到它自己的路径,例如

endpoints.MapHub<ChatHub>("/chat");

but in my case the notification icon is on the top navbar which is shared by the whole app and visible at all time, like in Facebook for example.但在我的情况下,通知图标位于顶部导航栏上,由整个应用程序共享并且始终可见,例如在 Facebook 中。 I tried mapping it to /_Host or / but it throws exceptions when I try to build the ConnectionHub that the url could not be determined.我尝试将其映射到/_Host/ ,但是当我尝试构建无法确定 url 的ConnectionHub时,它会引发异常。

The line endpoints.MapBlazorHub();线endpoints.MapBlazorHub(); says it maps the blazorhub to the default path, do i have to use this one?说它将 blazorhub 映射到默认路径,我必须使用这个吗? if so, how?如果是这样,怎么做?

Think of endpoints.MapHub<ChatHub>("/chat") like telling the server: "Hey. Start listening for SignalR connections at this address!".想想endpoints.MapHub<ChatHub>("/chat")就像告诉服务器:“嘿。开始在这个地址监听 SignalR 连接!”。

In order to listen for notification from your server you create a HubConnection that points to /chat .为了侦听来自服务器的通知,您创建了一个指向/chatHubConnection Before you start the connection with hubConnection.StartAsync() , you should register your events with hubConnection.On() .在使用hubConnection.StartAsync()开始连接之前,您应该使用hubConnection.On()注册您的事件。

Take a look at the article linked by Brian in the comments.看看 Brian 在评论中链接的文章。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM