2013-11-22 103 views
9

Signalr不加載我集線器:SignalR:錯誤加載樞紐

SignalR: Error loading hubs. Ensure your hubs reference is correct, e.g. <script src='/signalr/js'></script>. 

我打電話startup configurationapp.MapSignalR();

我加入到我的CSHTML:

<script src="~/Scripts/jquery-1.9.1.js"></script> 
<script src="~/Scripts/jquery.signalR-2.0.0.js"></script> 
<script src="~/signalr/hubs" type="text/javascript"></script> 

<script> 

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

</script> 

回答

7

確保你的啓動類有這個屬性:

[assembly: OwinStartup(typeof(MyStartupClass))] 

您可以在web.config中定義Owin啓動類以及:

<appSettings> 
    <add key="owin:appStartup" value="MyNamespace.MyStartupClass" /> 
</appSettings> 
+0

現在我得到也:GET HTTP://本地主機:18937/signalr /集線器500(內部服務器錯誤) – daniel

+0

嘗試加入這個到Web.config:'< httpRuntime targetFramework =「4.5」/>' –

+0

已經存在。我也刪除並添加了Signalr nuget包,但沒有成功 – daniel

8

訪問您的網站,例如http://localhost/signalr/hubs,看看您是否能在那裏獲得更好的錯誤描述。我的問題是我在我的中心有一個通用的方法。

public void Update<T>(T objectToUpdate) where T : class 
1

還要確保在啓動類中添加:

app.MapSignalR(); 

解決了我的問題

0

服務器必須知道你的啓動類是

一種選擇是像Rob wrotes:

[assembly: OwinStartup(typeof(MyStartupClass))] 

但也有其他可能達到你的要求。從微軟的文檔(docs.microsoft.com/en-us/aspnet/core/fundamentals/startup):

或者,您可以定義將通過調用UseStartup無論使用環境的固定啓動類。 這是推薦的方法。

例子:

public class Program 
    { 
     public static void Main(string[] args) 
     {  
      BuildWebHost(args).Run(); 
     } 

     public static IWebHost BuildWebHost(string[] args) => 
      WebHost.CreateDefaultBuilder(args) 
       .UseStartup<Startup>() 
       .Build(); 
    }