SignalR:加载集线器时出错

信号器不加载我的集线器:

SignalR: Error loading hubs. Ensure your hubs reference is correct, eg . 

我正在调用app.MapSignalR();startup configuration

我添加到我的cshtml:

     $(document).ready(function () { window.hubReady = $.connection.hub.start(); });  

确保您的启动类具有以下属性:

 [assembly: OwinStartup(typeof(MyStartupClass))] 

您也可以在web.config中定义Owin启动类:

    

访问您的站点,例如http:// localhost / signalr / hubs ,看看是否可以在那里获得更好的错误描述。 我的问题是我的中心有一个通用的方法。

 public void Update(T objectToUpdate) where T : class 

还要确保在Startup类中添加:

 app.MapSignalR(); 

解决了我的问题

服务器必须知道启动类的位置

一个选择就像Rob wrotes:

 [assembly: OwinStartup(typeof(MyStartupClass))] 

但是还有其他可能性可以满足你的要求。 来自Microsoft Docs(docs.microsoft.com/en-us/aspnet/core/fundamentals/startup):

或者,您可以通过调用UseStartup来定义将在不考虑环境的情况下使用的固定Startup类。 这是推荐的方法。

例:

 public class Program { public static void Main(string[] args) { BuildWebHost(args).Run(); } public static IWebHost BuildWebHost(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup() .Build(); }