错误:无法完成与服务器的协商:错误:找不到

问题描述 投票:0回答:1

我将SignalR与ASP.NET Boilerplate .NET Core 3.1一起使用,但遇到此问题

错误:无法完成与服务器的协商:错误:找不到

我如何在不进行跳过协商的情况下解决此问题(解决方案提及here]

zone-evergreen.js:2845 POSThttp://localhost:21021/signalr/negotiate?enc_auth_token=wNYmO41%2F再显示162帧signalr.min.js:16 [2020-06-07T10:17:31.634Z]错误:无法启动连接:错误:未找到

这里是Angular代码:

  ngOnInit(): void {
    this.renderer.addClass(document.body, 'sidebar-mini');

    //SignalRAspNetCoreHelper.initSignalR();
     // SignalRAspNetCoreHelper.initSignalR(); // Replace this line with the block below
     SignalRAspNetCoreHelper.initSignalR(() => {
      var chatHub = null;

      abp.signalr.startConnection(abp.appPath + 'signalr-myChatHub', function (connection) {
          chatHub = connection; // Save a reference to the hub


          connection.on('getMessage', function (message) { // Register for incoming messages
              console.log('received message: ' + message);
          });
      }).then(function (connection) {
          abp.log.debug('Connected to myChatHub server!');
          abp.event.trigger('myChatHub.connected');
      });

      abp.event.on('myChatHub.connected', function() { // Register for connect event
          chatHub.invoke('sendMessage', "Hi everybody, I'm connected to the chat!"); // Send a message to the server
      });
  });
}

这里是.NET Core类代码:

using Abp.Dependency;
using Abp.Runtime.Session;
using Castle.Core.Logging;
using Microsoft.AspNetCore.SignalR;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace HealthMapControlPanel.ChatAppService
{
   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);
        }
    }
}

Startup.cs类相关的代码:

public void Configure(IApplicationBuilder app,  ILoggerFactory loggerFactory)
{
  app.UseSignalR(routes =>
            {
                routes.MapHub<MyChatHub>("/signalr-myChatHub");
            });

 app.UseEndpoints(endpoints =>
            {
                endpoints.MapHub<MyChatHub>("/signalr-myChatHub");
                endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");
                endpoints.MapControllerRoute("defaultWithArea", "{area}/{controller=Home}/{action=Index}/{id?}");
            });
}

这是Web浏览器控制台屏幕快照:

enter image description here

typescript signalr aspnetboilerplate .net-core-3.1 asp.net-boilerplate
1个回答
2
投票
您应还原endpoints.MapHub<AbpCommonHub>("/signalr");
© www.soinside.com 2019 - 2024. All rights reserved.