$ .connection.Hub取消定义

时间:2016-06-28 11:03:49

标签: c# asp.net signalr

我在框架工作4.0中使用信号r。当我调用我的集线器类(testhub)时,它显示为undefine。我的jquery代码如下所示

<head runat="server">
        <title></title>
        <script src='<%: ResolveClientUrl("Scripts/jquery-1.6.4.js") %>'></script>
             <script src='<%: ResolveClientUrl("Scripts/jquery-1.6.4.min.js") %>'></script>

             <script src='<%: ResolveClientUrl("Scripts/jquery.signalR-1.0.0-rc1.js") %>'></script>   
            <script src='<%: ResolveClientUrl("Scripts/jquery.signalR-1.0.0-rc1.min.js") %>'></script>

             <script src='<%: ResolveClientUrl("signalr/hubs") %>'></script>
    </head>
    <body>
        <form id="form1" runat="server">
    var data = $.connection.tenantHub;
                    $.connection.hub.logging = true;
                    console.log(data); //undefine

            </script>
    </form>

我有global.asax,但没有通过

上的任何错误
void Application_Start(object sender, EventArgs e) 
    {
        // Code that runs on application startup
        RouteTable.Routes.MapHubs();
    }  

我在Hubs文件夹中有hub类,如下所示。

[HubName("tenantHub")]
public class testhub:Hub
{
    public void send(string message)
    {
        Clients.All.addmessage(message);
    }
}

我的包裹如下:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="jQuery" version="1.6.4" targetFramework="net40" />
  <package id="Microsoft.AspNet.SignalR" version="1.0.0-rc1" targetFramework="net40" />
  <package id="Microsoft.AspNet.SignalR.Core" version="1.0.0-rc1" targetFramework="net40" />
  <package id="Microsoft.AspNet.SignalR.JS" version="1.0.0-rc1" targetFramework="net40" />
  <package id="Microsoft.AspNet.SignalR.Owin" version="1.0.0-rc1" targetFramework="net40" />
  <package id="Microsoft.AspNet.SignalR.SystemWeb" version="1.0.0-rc1" targetFramework="net40" />
  <package id="Microsoft.Owin.Host.SystemWeb" version="1.0-rc1" targetFramework="net40" />
  <package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net40" />
  <package id="Newtonsoft.Json" version="4.5.4" targetFramework="net40" />
  <package id="Owin" version="1.0" targetFramework="net40" />
</packages>

1 个答案:

答案 0 :(得分:0)

.net Framework 4.0的最后兼容信号器版本是1.2.2:

您是否可以通过打开NuGet包管理器控制台并键入:

来尝试更新您的Signalr版本
Install-Package Microsoft.AspNet.SignalR.Client -Version 1.2.2
Install-Package Microsoft.AspNet.SignalR -Version 1.2.2

基于jquery 1.6.4 Fwk 4和signalR 1的完整聊天示例:http://www.bluelemoncode.com/2013/02/default.aspx

此外,不要解决两次js脚本(根据您的环境,只保留缩小或未压缩):

<script src='<%: ResolveClientUrl("Scripts/jquery-1.6.4.min.js") %>'></script>                 
<script src='<%: ResolveClientUrl("Scripts/jquery.signalR-1.0.0-rc1.min.js") %>'></script>