Click here to Skip to main content
15,889,507 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am looking to add push notifications which will push status messages to client browser only when specific functions are called within a button's click event. The client javascript methods which will accept signalr sent messages are located in PageA.aspx which looks like this.

<script src="Scripts/jquery-1.6.4.js"></script>
<script src="Scripts/jquery.signalR-2.2.0.js"></script>
<script type="text/javascript" >
$(function () {
var connection = $.hubConnection();
var hub = connection.createHubProxy("hitCounter");
hub.on("onRecordHit", function (hitCount) {
$('#hitCountValue').text(hitCount);
});

connection.start(function () {
hub.invoke('recordHit');
});
});
</script>

The Hub Code looks like this

C#
//[HubName("hitCounter")]
   public class HitCounterHub: Hub
   {
       static int _hitcount = 0;

       public void RecordHit()
       {
           _hitcount += 1;
           Clients.All.onRecordHit(_hitcount);
       }
   }



The code fired on the browser with this example up until I attempted to call the RecordHit() Method from another webpage(PageB.aspx) By doing the following on PageB's Button1_Click event.

XML
var myhubContext = GlobalHost.ConnectionManager.GetHubContext<HitCounterHub>();
            myhubContext.Clients.All.RecordHit();


Is there something I am missing here?
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900