【发布时间】:2014-03-05 18:30:11
【问题描述】:
我有一个 Web 窗体应用程序和测试,以了解 SignalR 如何满足我的一项要求。我的中心代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.AspNet.SignalR;
namespace SignalRTest.Hubs
{
public class NotificationHub : Hub
{
public static readonly System.Timers.Timer _Timer = new System.Timers.Timer();
public NotificationHub()
{
var myInfo = Context.QueryString["myInfo"];
_Timer.Interval = 2000;
_Timer.Elapsed += TimerElapsed;
_Timer.Start();
}
void TimerElapsed(object sender, System.Timers.ElapsedEventArgs e)
{
Random rnd = new Random();
int i = rnd.Next(0, 2);
var hub = GlobalHost.ConnectionManager.GetHubContext("NotificationHub");
hub.Clients.All.Alert(i);
}
}
}
我的客户电话:
<script type="text/javascript">
$(function () {
var logger = $.connection.notificationHub;
logger.client.Alert = function (msg) {
if (msg == 1) {
$("#HyperLink1").show();
$("#HyperLink2").hide();
}
else {
$("#HyperLink1").hide();
$("#HyperLink2").show();
}
};
$.connection.hub.qs = "myInfo=12345";
$.connection.hub.start();
});
</script>
但是,由于某种原因,当检查服务器代码(在集线器中)上的上下文时,它为空,所以我无法检索查询字符串值。有什么想法吗?
【问题讨论】:
标签: c# signalr signalr-hub signalr.client