javascript - SignalR - Unable to get property 'client' of undefined or null reference -


i having problems using signalr in existing web application. receiving javaruntime exception "unable property 'client' of undefined or null reference" because when try retrieve hub $.connection object, returning null.

before post code, wanted supply background , things have tried: - if run project locally, works fine. when deploy project iis location have issues. - have verified hub name correctly camel cased. again, works fine locally, , throws error after have deployed project iis. - have confirmed javascript has loaded. jquery library referenced once, , loads fine. signalr javascript, , dynamically created signalr/hubs. - if create new project, , run same code new web application running web app under existing web application, works fine (same code being used, in new project).

anyone have thoughts on problem is?

hub code:

imports microsoft.aspnet.signalr  public class testhub     inherits hub      public sub connect()         try             clients.caller.onconnect(context.connectionid)         catch ex exception             logmessage("error connecting hub", 0, 0, "error")         end try     end sub  end class 

web page code:

<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server">     <title></title>     <script src="scripts/jquery-1.6.4.min.js"></script>     <!--reference signalr library. -->     <script src="scripts/jquery.signalr-1.1.3.js"></script>     <!--reference autogenerated signalr hub script. -->     <script src="signalr/hubs"></script>     <script type="text/javascript">         $(function () {             // declare proxy reference hub.              var thub = $.connection.testhub;              registerclientmethods(thub);              // start hub             $.connection.hub.start().done(function () {                 registerevents(thub);                 thub.server.connect();                 alert('connected!');             });         });           function registerclientmethods(thub) {             thub.client.onconnect = function (id) {                 $('#lblconnectionid').text(id);             }         }          function registerevents() {          }     </script> </head> <body>     <form id="form1" runat="server">     <div>         <asp:label id="lblconnectionid" runat="server" />     </div>     </form> </body> </html> 

global.asax code:

imports system.web.routing imports microsoft.aspnet.signalr  public class global_asax   inherits system.web.httpapplication     sub application_start(byval sender object, byval e eventargs)     ' fires when application started     try     ' register default hubs route: ~/signalr/hubs     routetable.routes.maphubs()     catch ex exception     logmessage("error initializing signalr: " & ex.message, 0, 0, "error")     end try end sub ... 

so now, when go page signalrtest.aspx, line thub.client.onconnected = ... throws javascript error: "unable property 'client' of undefined or null reference"

does know might causing this? thank you.

[edit] - after comparing working signalr/hubs.js file non-working file, found following piece missing:

proxies.testhub= this.createhubproxy('testhub');      proxies.testhub.client = { };     proxies.testhub.server = {         connect: function () {             return proxies.transactionhub.invoke.apply(proxies.testhub, $.merge(["connect"], $.makearray(arguments)));          }     }; 

any thoughts on why not included in signalr/hubs.js file? calling maphubs() in global.asax...

thanks!

[fix] deleted bin folder of destination web application, , redeployed. still not sure different. .dlls same. works though. odd.

i encountered error when trying debug run web application after publishing vs 2012 iis 7.5. after hair pulling, realised problem fact did not change jquery script , signalr paths when deploying.

to solve issue had add virtual directory name ("testingchat") path of script tags jquery , signalr.

e.g. this:

<script src="scripts/jquery-1.8.2.min.js" ></script> <script src="/signalr/hubs"></script> 

to

<script src="/testingchat/scripts/jquery-1.8.2.min.js" ></script> <script src="testingchat/signalr/hubs"></script> 

Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -