2016-08-19 96 views
1

我有Windows 10操作系统并安装了Chrome,Firefox和Internet Explorer浏览器。我尝试在asp.net MVC中使用SignalR通知系统构建应用程序。当我在Firefox下运行我的应用程序时,一切正常。但在Internet Explorer和谷歌浏览器下无法使用。 我debbuging时发现的是,我的数据库中更改时,应用程序不会正确执行下面的方法:SignalR不适用于Chrome和Internet Explorer

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下反应。

你能帮我解决这个问题吗?

+0

我怀疑你的代码无法在Chrome和IE浏览器中建立集线器连接。可能值得检查失败的浏览器中的控制台以查看是否记录了错误。 – Luke

+0

谢谢,但它似乎工作。 – hegendroffer

+0

是否有错误? :) – Luke

回答

1

我已经解决了这个问题。 原来,我不得不在我的NotificationHub类中添加一行:

[HubName("notificationHub")] 

现在看起来以下,这解决了我的问题。

[HubName("notificationHub")] 
public class NotificationHub : Hub 
{ 
    //public void Hello() 
    //{ 
    // Clients.All.hello(); 
    //} 
} 
相关问题