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...
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
either in your global.asax application start or using some startup injector like WebActivatorEx.
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
initialized and
defined with the function names same as that declared in the c# HubProxy. And all of these present under the following prototype decalration .
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!!