Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
578 views
in Technique[技术] by (71.8m points)

javascript - Implementing The SingalR Sample Into An ASP.Net WEB SITE APPLICATION -- Error In JS

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.)

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.)

Here is the error I get

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

Here is the javascript that the error is thrown with

// 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();
    }
});

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>

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.

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.

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...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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() 

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) All the SIgnalr related dlls are of compatible versions. This wont be an issue if you have installed with library package manager console.

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 

initialized and

proxies.stockTicker.server 

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) 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.

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

All the Best!!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...