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
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.
var myhubContext = GlobalHost.ConnectionManager.GetHubContext<HitCounterHub>();
myhubContext.Clients.All.RecordHit();
Is there something I am missing here?