当我在IIS上托管angular应用程序时,我面临着signalr的问题,它一直在控制台显示以下错误。
[2020-05-31T08:09:00.838Z] Error: Connection disconnected with error 'Error: WebSocket closed with status code: 1006 ().'.
当我使用nodeJs托管angular应用程序时,它工作正常,但我需要在IIS上托管angular应用程序。
我使用"@microsoftsignalr "和aspcore 3.1。
我的代码示例 angular。
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);
}
你必须在IIS设置中启用websocket。https:/docs.microsoft.comen-usiisconfigurationsystem.webserverwebsocket。