WebSocket 错误:HTTP 响应不正确。状态码 400,错误请求

我尝试为 ASP.NET Core 实现 SignalR,如下所述:https ://aspnetboilerplate.com/Pages/Documents/SignalR-AspNetCore-Integration


但我总是得到一个错误。浏览器控制台输出:


DEBUG: 

Starting connection using WebSockets transport

Information: Normalizing '/signalr-myChatHub' to 'http://localhost:62114/signalr-myChatHub'

SCRIPT12008: WebSocket Error: Incorrect HTTP response. Status code 400, Bad Request

我正在使用所有软件包 3.6.2 和 Abp.AspNetCore.SignalR 3.6.2-preview6 的最新版本。


Web.Host/Startup.cs:


#elif FEATURE_SIGNALR_ASPNETCORE

    app.UseSignalR(routes =>

    {

        routes.MapHub<AbpCommonHub>("/signalr");

        routes.MapHub<MyChatHub>("/signalr-myChatHub"); // Prefix with '/signalr'

    });

#endif

复制粘贴MyChatHub.cs:


public class MyChatHub : Hub, ITransientDependency

{

    public IAbpSession AbpSession { get; set; }


    public ILogger Logger { get; set; }


    public MyChatHub()

    {

        AbpSession = NullAbpSession.Instance;

        Logger = NullLogger.Instance;

    }


    public async Task SendMessage(string message)

    {

        await Clients.All.SendAsync("getMessage", string.Format("User {0}: {1}", AbpSession.UserId, message));

    }


    public override async Task OnConnectedAsync()

    {

        await base.OnConnectedAsync();

        Logger.Debug("A client connected to MyChatHub: " + Context.ConnectionId);

    }


    public override async Task OnDisconnectedAsync(Exception exception)

    {

        await base.OnDisconnectedAsync(exception);

        Logger.Debug("A client disconnected from MyChatHub: " + Context.ConnectionId);

    }

}

或多或少复制粘贴的视图:


@using EMetall.Web.Startup


@section scripts

{

    <environment names="Development">

        <script src="~/lib/signalr-client/signalr.min.js"></script>

        <script src="~/lib/abp-web-resources/Abp/Framework/scripts/libs/abp.signalr-client.js"></script>

    </environment>


千巷猫影
浏览 221回答 2
2回答

Cats萌萌

您需要使用以下兼容版本:Abp.AspNetCore.SignalR(目前为 3.6.2-preview6),来自@aspnet/signalr 的signalr.min.js(当前为 1.0.0-rc1-update1),以及abp.signalr-client.js(目前为 3.6.2)将在abp-web-resources 上发布。
打开App,查看更多内容
随时随地看视频慕课网APP