【问题标题】:Detected a connection attempt to an ASP.NET SignalR Server检测到与 ASP.NET SignalR 服务器的连接尝试
【发布时间】:2020-08-03 20:23:12
【问题描述】:

我有一个在 vue-cli3 中创建的 vuejs 应用程序和在 .Net Framework 4.6.x 中创建的带有 SignalR 的 ASP.Net WebAPI

我在连接到 SignalR 时遇到问题,它抛出错误“检测到与 ASP.NET SignalR 服务器的连接尝试。此客户端仅支持连接到 ASP.NET Core SignalR 服务器”。

根据此链接:Detected a connection attempt error,我应该使用signalR 而不是@aspnet/signalr。但是当我尝试使用它时,它会抛出一个 jquery 引用错误。我真的应该在这里使用 Jquery 吗?我已经为此卡了 2 天。

我的 Vue 组件:

import { HubConnectionBuilder, LogLevel } from 'signalr'
// import { HubConnectionBuilder, LogLevel } from '@aspnet/signalr' <--- I already tried this,same error
created() {
    const connection = new HubConnectionBuilder()
                  .withUrl('https://localhost:44356/chat-hub')
                  .configureLogging(LogLevel.Information)
                  .build()

    connection.start()
}

我的 Startup.cs

public void Configuration(IAppBuilder app)        
    {

        app.Map("/chat-hub",
            x =>
            {
                x.UseCors(CorsOptions.AllowAll);
                var hubConfig = new HubConfiguration
                {
                };

                x.RunSignalR(hubConfig);

            }
                            
        );

        app.MapSignalR();
        
    }

【问题讨论】:

标签: asp.net-web-api signalr signalr.client


【解决方案1】:

问题是你使用了 ASP.NET Server 组件和 .NET Core Client。

您不能混合使用它们,因为它们不兼容。

由于您是在 .Net Framework 4.6.x 上构建并拥有 ASP.NET 服务器,因此您需要下载 ASP.NET 客户端,是的,确实需要 JQuery。

如果您不想使用 JQuery,则需要执行相反的操作,将您的服务器组件替换为 .NET Core 3.1 并保持(更新)到相同的 .NET Core 客户端。请注意,这不是简单的替换,您需要更新代码的许多方面。

【讨论】:

    猜你喜欢
    • 2019-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-09
    • 2015-06-03
    相关资源
    最近更新 更多