SignalR 2.2.0 MVC 4错误客户端未定义 [英] SignalR 2.2.0 MVC 4 error client undefined

查看:89
本文介绍了SignalR 2.2.0 MVC 4错误客户端未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将近12个小时没有成功,我已经在Web Project中尝试了此代码,并且可以正常工作,但是当与我的MVC应用程序集成时,它给了我错误

It's almost 12 hrs no success, I have tried this code in Web Project and it worked but when integrating with my MVC application it is giving me errors

GET http://localhost:50843/signalr/Hubs 

DashBoard:553 Uncaught TypeError: Cannot read property 'client' of undefined(anonymous function) @ DashBoard:553

通常在找不到集线器脚本时会发生此错误,我尝试了许多修复程序,但是我的代码没有运气.

This error occurs usually when the hub script is not found I have tried many fixes but no luck here is my code.

项目结构

参考

ChatHub.cs (我省略了方法的实现)

ChatHub.cs (I have omitted the method implementation)

 using System;
    using System.Web;
    using Microsoft.AspNet.SignalR;
    using SignalRTest;
    using System.Threading.Tasks;
    using System.Linq;
    using System.Web.Security;

    namespace SignalRChat

    {
        public class ChatHub : Hub
        {
        }
    }

Startup.cs

Startup.cs

using Microsoft.AspNet.SignalR;
using Microsoft.Owin;
using Owin;

[assembly: OwinStartup(typeof(SignalRChat.Startup))]
namespace SignalRChat
{
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            app.MapSignalR();
        }
    }
}

_Layout.cshtml

_Layout.cshtml

这是无法调用客户端对象的问题区域.任何帮助将不胜感激.

This is the problem area not able to invoke the client object.Any help will be greatly appreciated.

谢谢.

推荐答案

我实际上在Startup.cs文件中应用了一个断点,以查看它是否是方法MapSignalR()的调用,因为该方法负责调用集线器脚本动态.令我惊讶的是,该方法没有被调用.

I actually applied a break point at Startup.cs file to see if it is invokin gthe method MapSignalR() as this is the method which is responsible for invoking the hub script dynamically. And to my surprise this method is not getting invoked.

因此,经过更多的努力,我意识到我缺少这些引用Microsoft.Owin.Host.SystemWebMicrosoft.Owin.Security,这些引用负责通过Owin调用Startup类方法.

So after some more efforts I realized I was missing these references Microsoft.Owin.Host.SystemWeb and Microsoft.Owin.Security that are responsible to invoke the Startup class method through Owin.

这篇关于SignalR 2.2.0 MVC 4错误客户端未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆