实施SingalR样品放入一个ASP.Net WEB SITE应用 - 错误在JS [英] Implementing The SingalR Sample Into An ASP.Net WEB SITE APPLICATION -- Error In JS

查看:162
本文介绍了实施SingalR样品放入一个ASP.Net WEB SITE应用 - 错误在JS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现的SignalR到我的ASP.Net网站项目。 (这是现有的应用程序,这是一个网站项目,并且不能改变到是一个Web应用程序。)

I am trying to implement the SignalR into my ASP.Net "WEB SITE PROJECT". (This is an existing application and it is a Web Site Project, and can not be changed over to be a Web Application.)

我收到以下错误,当我尝试运行SignalR样品code。 (这是基本的股票代码样本。只是想确认我有正确安装的一切之前,我开始实施到现有的code这一点。)

I get the following error when I try to run the SignalR Sample code. (This is the basic stock ticker sample. Just wanting to verify I have everything setup correctly before I start implementing this into my existing code.)

Unhandled exception at line 71, column 5 in http://localhost:49218/SchoolFinancial/SignalR.Sample/SignalR.StockTicker.js

0x800a138f - Microsoft JScript runtime error: Unable to get value of the property 'client': object is null or undefined

下面是引发该错误使用JavaScript

// Add client-side hub methods that the server will call
$.extend(ticker.client, {
    updateStockPrice: function (stock) {
        var displayStock = formatStock(stock),
            $row = $(rowTemplate.supplant(displayStock)),
            $li = $(liTemplate.supplant(displayStock)),
            bg = stock.LastChange === 0
                ? '255,216,0' // yellow
                : stock.LastChange > 0
                    ? '154,240,117' // green
                    : '255,148,148'; // red

        $stockTableBody.find('tr[data-symbol=' + stock.Symbol + ']')
            .replaceWith($row);
        $stockTickerUl.find('li[data-symbol=' + stock.Symbol + ']')
            .replaceWith($li);

        $row.flash(bg, 1000);
        $li.flash(bg, 1000);
    },

    marketOpened: function () {
        $("#open").prop("disabled", true);
        $("#close").prop("disabled", false);
        $("#reset").prop("disabled", true);
        scrollTicker();
    },

    marketClosed: function () {
        $("#open").prop("disabled", false);
        $("#close").prop("disabled", true);
        $("#reset").prop("disabled", false);
        stopTicker();
    },

    marketReset: function () {
        return init();
    }
});

这里在web.config设置更改说是让一个网站项目SignalR工作

(这在web.config中的以下部分的内侧)

Here is the Web.Config setting change that is to allow SignalR work with a Web Site project

(This is inside of the following section of the Web.Config )

  <modules runAllManagedModulesForAllRequests="true">
  </modules>

我是新来使用SignalR从我已经从previous后发现,这应该可以解决我的问题,如果我能得到它的工作。

I am NEW to using SignalR and from what I have found from a previous post, this should solve my issue if I can get it working.

因此​​,如果任何人有在ASP.Net我将不胜AP preciate任何建议/建议在网站项目使用SignalR的经验。

So, if anyone has any experience with using the SignalR in a Web Site Project in ASP.Net I would greatly appreciate any suggestions / recommendations.

如果它的事项或没有,但我使用Visual Studio 2012(ASP.Net / C#)和我的网站是在.NET Framework 4.5版不知道。

Not sure if it matters or not, but I am using Visual Studio 2012 (ASP.Net / C#) and my web site is on the .Net Framework 4.5 version.

在此先感谢您的帮助...

Thanks in advance for your help...

推荐答案

您收到此错误,可能是因为任何的原因如下: -

You are getting this error probably because of the any of the following reasons:-

1)yourbaseurl / signalr /集线器正在给404可以验证在Chrome控制台页面加载后。如果您收到此错误,你需要确保集线器路由映射。使用

1) yourbaseurl/signalr/hubs is giving 404. You can verify that in the chrome console after the page is loaded. If you are getting this error you need to make sure that the Hub routes are mapped. using

RouteTable.Route.MapHubs() 

无论是在您的Global.asax的应用程序启动或使用一些启动喷油器像WebActivatorEx。

either in your global.asax application start or using some startup injector like WebActivatorEx.

 void Application_Start(object sender, EventArgs e) 
    {
        // Code that runs on application startup
        RouteTable.Routes.MapHubs();
    }

2)所有SIgnalr相关的DLL是兼容版本。这不会是一个问题,如果你已经有库软件包管理器控制台安装。

2) All the SIgnalr related dlls are of compatible versions. This wont be an issue if you have installed with library package manager console.

3)如果上述步骤不是问题则问题是,客户端代理没有得到正确生成。这意味着,如果你打yourbaseurl / signalr /集线器,你应该可以看到名为相同骆驼情况下,C#类枢纽名义注册的轮毂以及

3) if above steps is not the issue then the issue is that the client proxies are not getting generated properly. This means if you hit yourbaseurl/signalr/hubs you should be able to see the hub registered with the name same as the c# hub class name in camel case and

proxies.stockTicker.client 

初​​始化和

proxies.stockTicker.server 

用相同在c#HubProxy声明的函数名所定义。而所有的原型如下decalration在这些present的。

defined with the function names same as that declared in the c# HubProxy. And all of these present under the following prototype decalration .

 $.hubConnection.prototype.createHubProxies

4)如果你是不是能够得到按照步骤3试的类文件放置在SignalR.StockTicker到应用code生成的代理。

4) If you are not able to get the proxy generated as per step 3 try placing the class files in the SignalR.StockTicker in to the AppCode.

请注意: - 我只是尝试,并获得样品中Asp.Net 4.5网站工作

Note:- I just tried and got the sample working in Asp.Net 4.5 website.

一切顺利!

这篇关于实施SingalR样品放入一个ASP.Net WEB SITE应用 - 错误在JS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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