【发布时间】:2016-08-19 13:16:26
【问题描述】:
我有 Windows 10 操作系统并安装了 Chrome、Firefox 和 Internet Explorer 浏览器。我尝试在 asp.net MVC 中使用 SignalR 通知系统构建应用程序。当我在 Firefox 下运行我的应用程序时,一切正常。但是在 Internet Explorer 和 Google Chrome 下它不起作用。 我在调试时发现,当我的数据库发生更改时,应用程序确实正确执行以下方法:
private void sqlDep_OnChange(object sender, SqlNotificationEventArgs e)
{
if(e.Type == SqlNotificationType.Change)
{
SqlDependency sqlDep = sender as SqlDependency;
sqlDep.OnChange -= sqlDep_OnChange;
var notificationHub = GlobalHost.ConnectionManager.GetHubContext<NotificationHub>();
notificationHub.Clients.All.notify("added");
DateTime dt = DateTime.Now;
DateTime dt1 = DateTime.UtcNow.AddHours(2);
RegisterNotification(dt);
}
}
但是什么时候到达
notificationHub.Clients.All.notify("added");
下面的 JavaScript:
notificationHub.client.notify = function (message) {
if (message && message.toLowerCase() == "added") {
updateNotificationCount();
}
}
没有反应,而在 Firefox 下它会反应。
你能帮我解决这个问题吗?
【问题讨论】:
-
我怀疑您的代码无法在 Chrome 和 IE 中建立集线器连接。可能值得检查故障浏览器中的控制台以查看是否记录了错误。
-
谢谢,但它似乎正在工作。
-
有错误吗? :)
-
我添加了 var notificationHub = $.connection.notificationHub; $.connection.hub.start().done(function () { console.log('通知中心已启动'); });并且控制台“通知中心已启动”中有信息
标签: javascript c# asp.net-mvc signalr