小编Gen*_*001的帖子

websocket握手期间的asp.net核心信号器错误

对不起,我的英语不好。我正在尝试从 SPA 应用程序 (Vue.JS) 连接到 SignalR Hub。

来自客户端的代码:

this.hubConnection = new HubConnectionBuilder()
    .withUrl('http://localhost:*****/testhub')
    .configureLogging(LogLevel.Information)
    .build()
Run Code Online (Sandbox Code Playgroud)

我收到一个错误:错误:无法完成与服务器的协商:SyntaxError:Unexpected token < in JSON at position 0

然后我尝试:

this.hubConnection = new HubConnectionBuilder()
    .withUrl('http://localhost:*****/testhub', {
      skipNegotiation: true,
      transport: HttpTransportType.WebSockets
    })
    .configureLogging(LogLevel.Information)
    .build()
Run Code Online (Sandbox Code Playgroud)

什么都没有改变(但我收到另一个错误):

WebSocket 连接到“ws://localhost:50523/testhub”失败:WebSocket 握手期间出错:意外响应代码:200

我在 Startup.cs 中检查了 UseWebsockets。我也尝试在客户端更改 SignalR 版本,但无法解决问题。当我尝试在多页应用程序中连接 SignalR 时,我没有看到它。我第一次拥有它。

我做错了什么?

启动文件

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.SpaServices.Webpack;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.WebSockets;
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.IdentityModel.Tokens;
using Microsoft.AspNetCore.Authorization;
using Newtonsoft.Json; …
Run Code Online (Sandbox Code Playgroud)

c# websocket signalr asp.net-core

5
推荐指数
1
解决办法
9457
查看次数

标签 统计

asp.net-core ×1

c# ×1

signalr ×1

websocket ×1