在 Startup.cs 文件中添加以下代码:
services.AddSignalR();
app.UseEndpoints(endpoints =>
{
endpoints.MapHub("/chatHub");
});
@code {
[Inject] HubConnectionBuilder hubConnectionBuilder { get; set; }
protected override async Task OnInitializedAsync()
{
var hubConnection = hubConnectionBuilder
.WithUrl(NavigationManager.ToAbsoluteUri("/chatHub"))
.Build();
await hubConnection.StartAsync();
}
}
上一篇:BlazorServer使用SignalR的客户端模式无法正常工作。
下一篇:BlazorServerSide'WebsocketConnectionto'{url}'failedoccured'whenhostwithNginxProxy