SignalR 不适用于 Chrome 和 Internet Explorer
SignalR doesn't work with Chrome and Internet Explorer
我有 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 下它有反应。
你能帮我解决这个问题吗?
我已经解决了问题。
结果我不得不在我的 NotificationHub class:
中添加一行
[HubName("notificationHub")]
现在看起来如下,这解决了我的问题。
[HubName("notificationHub")]
public class NotificationHub : Hub
{
//public void Hello()
//{
// Clients.All.hello();
//}
}
我有 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 下它有反应。
你能帮我解决这个问题吗?
我已经解决了问题。 结果我不得不在我的 NotificationHub class:
中添加一行[HubName("notificationHub")]
现在看起来如下,这解决了我的问题。
[HubName("notificationHub")]
public class NotificationHub : Hub
{
//public void Hello()
//{
// Clients.All.hello();
//}
}