【发布时间】:2020-05-31 08:12:10
【问题描述】:
在 IIS 上托管 Angular 应用程序时,我遇到信号器问题,它一直在控制台上显示以下错误:
[2020-05-31T08:09:00.838Z] Error: Connection disconnected with error 'Error: WebSocket closed with status code: 1006 ().'.
请记住,一旦我使用 nodeJs 托管了 Angular 应用程序,它就可以正常工作,但我需要在 IIS 上托管 Angular 应用程序。
我正在使用“@microsoft/signalr”和 aspcore 3.1
我的代码示例角度:
constructor(private fb: FormBuilder, private router: Router) {
//establish a new connection on the logging user group
this.signalRConnection = new signalR.HubConnectionBuilder()
.configureLogging(signalR.LogLevel.Information)
.withUrl(this.hubUrl)
.build();
this.signalRConnection.start().then(() => {
this.session.id = this.signalRConnection.connectionId;
this.signalRConnection.send("RegisterOnlineUser", this.session, 'title', 'url');
this.signalRConnection.send("GetOnlineUsers");
});
}
aspcore:
public async void registerOnlineUser(SessionInfo session)
{
await Groups.AddToGroupAsync(Context.ConnectionId, session.group);
await Clients.Group(Users).SendAsync("RegisterOnlineUser", session);
}
【问题讨论】:
-
你在前端使用什么样的库作为信号器?你的后端是nodejs还是其他?
-
你需要分享角度和核心部分代码来理解问题
-
我使用前端的“@microsoft/signalr”作为角度,我的后端是 asp.net core 3.1
-
@aspnet/signalr 适用于核心 api 。在我的应用程序中,我将此库用于角度
标签: angular asp.net-core websocket asp.net-core-signalr