问题描述
我用SignalR通知创建了一个ASP MVC 4应用程序。我通过IIS发布在本地以及在服务器上以调试模式运行它。这在大多数情况下(后面解释)在使用Internet Explorer 11时会发挥作用:
HTML1300:导航发生。
File:AllChanges
SignalR:窗口卸载,停止连接。
SignalR:停止连接。
SignalR:永久停止帧。
SignalR:触发ajax中止async = false。
SignalR:停止对活着的监控。
JQMIGRATE:迁移已安装,版本3.0.0
SignalR:客户端订阅集线器'prismhub'。
SignalR:与'/signalr/negotiate?clientProtocol=1.5&connectionData=%5B%7B%22name%22%3A%22prismhub%22%7D%5D'协商。
SignalR:serverSentEvents传输开始。
SignalR:此浏览器不支持SSE。
SignalR:serverSentEvents传输无法连接。试图回退。
SignalR:foreverFrame传输开始。
SignalR:绑定到iframe的加载事件。
SignalR:Iframe传输开始。
SignalR:foreverFrame传输连接。发起启动请求。
SignalR:开始请求成功。转换到连接状态。
SignalR:现在监控保持活动状态,警告超时值为13333.333333333332,保持活动超时值为20000,断开超时值为30000
连接到signalR hub
SignalR:foreverFrame传输尝试连接时超时。
** SignalR:触发集线器'prismHub'上的客户端集线器事件'sendUpdatedChange'。**
SignalR:窗口卸载,停止连接。
SignalR:停止连接。
SignalR:调用close()的EventSource。
SignalR:触发ajax中止async = false。
SignalR:停止对活着的监控。
JQMIGRATE:迁移已安装,版本3.0.0
SignalR:客户端订阅集线器'prismhub'。
SignalR:与'/signalr/negotiate?clientProtocol=1.5&connectionData=%5B%7B%22name%22%3A%22prismhub%22%7D%5D'协商。
SignalR:serverSentEvents传输开始。
SignalR:试图连接到SSE端点'http:// localhost:61159 / signalr / connect?transport = serverSentEvents& clientPro ... FNE6BKzqphux4& connectionData =%5B%7B%22name%22%3A%22prismhub%22% 7D%5D&安培; TID = 9' 。
SignalR:连接了EventSource。
SignalR:serverSentEvents传输已连接。发起启动请求。
SignalR:开始请求成功。转换到连接状态。
SignalR:现在监控保持活动状态,警告超时时间为13333.333333333332,活动超时时间为20000,断开超时时间为30000
连接到signalR hub
** SignalR:触发客户端集线器事件'sendUpdatedChange'在枢纽'prismHub'上。
SignalR:触发集线器prismHub上的客户端集线器事件'sendUpdatedChange'。
SignalR:触发枢纽prismHub上的客户端中心事件'sendUpdatedChange'。**
但我认为这些数据并没有改变(就像它在Internet Explorer中那样)。这个问题偶尔会发生在IE中。此外,刷新页面似乎会中断集线器连接。从IE控制台:
HTML1300:导航发生。
文件:AllChanges
JQMIGRATE:迁移已安装,版本3.0.0
SignalR:客户端订阅集线器'prismhub'。
SignalR:与'/signalr/negotiate?clientProtocol=1.5&connectionData=%5B%7B%22name%22%3A%22prismhub%22%7D%5D'协商。
SignalR:serverSentEvents传输开始。
SignalR:此浏览器不支持SSE。
SignalR:serverSentEvents传输无法连接。试图回退。
SignalR:foreverFrame传输开始。
SignalR:绑定到iframe的加载事件。
SignalR:Iframe传输开始。
SignalR:foreverFrame传输连接。发起启动请求。
SignalR:开始请求成功。转换到连接状态。
SignalR:现在监控保持活动状态,警告超时值为13333.333333333332,保持活动超时值为20000,断开超时值为30000
连接到signalR hub
SignalR:foreverFrame传输尝试连接时超时。
值得注意的是,这些请求对使用linq命中数据库的控制器进行ajax调用查询,返回数据列表:
查看JS
$(document).ready(function(){
FetchChanges();
notifications.client.sendUpdatedChange = function(){FetchChanges();};
}
函数FetchChanges(){
var model = $('#divChanges');
$ .ajax({
url:'/ Changes / AllChangesItems',
contentType:'application / html; charset:utf-8',
类型:'GET',
dataType:'html',
})
.done (function(result){
model.empty()。append(result);
})
}
$ b $ 控制器动作
public ActionResult AllChangesItems()
{
var username = CurrentUser()。UserName;
var changes = db.Cha nges;
List< ChangeListingViewModel> vm =新列表< ChangeListingViewModel>();
foreach(var c in changes)
{
vm.Add(new ChangeListingViewModel(c));
}
返回PartialView(_ ActiveItems,vm.ToList());
其中ChangeListingViewModel包含两个获取子行的linq查询(可以提供代码如果revelant):
然而,一个'简单'的查询似乎在IE和Chrome中正常工作,即推送通知触发JS函数更新view:
public void PinChange(int id)
{
CurrentUserDetails()。User.PinnedChanges。加入(db.Changes.Find(ID));
db.SaveChanges();
PrismHub.NotifyPinnedChange();
}
我的第一个想法是某种超时正在发生,但我不确定为什么浏览器会有所不同。任何建议将不胜感激。编辑:更新与集线器信息$ b $编辑2:更新集线器方法与其他片段一致。
strong>
以下是我的Hub类的片段:
Hub
[HubName(prismHub)]
public class PrismHub:Hub
{
private static IHubContext context = GlobalHost.ConnectionManager.GetHubContext< PrismHub>();
[HubMethodName(notifyUpdatedChange)]
public static void NotifyUpdatedChange()
{
context.Clients.All.sendUpdatedChange();
解决方案偶然发现了这个解决方案。经过几周的搜索,我遇到了这个帖子:
这个问题是通过解决这段JS中的查看:
$ b $ pre $ $ $ c $ $ $(document).ready(function(){
FetchChanges();
notifications .client.sendUpdatedChange = function(){FetchChanges();};
}
移动$(document).ready()之外的SignalR函数映射解决了它:
$(document).ready(function (){
FetchChanges();
}
notifications.client.sendUpdatedChange = function(){FetchChanges();};
我还没有发现这是一个问题,但我很高兴找到了解决方案。
I have created an ASP MVC 4 application with SignalR notifications. I run it in Debug mode locally and also on a server through IIS publish. This works mostly (explained later) as expected when using Internet Explorer 11:
HTML1300: Navigation occurred.
File: AllChanges
SignalR: Window unloading, stopping the connection.
SignalR: Stopping connection.
SignalR: Stopping forever frame.
SignalR: Fired ajax abort async = false.
SignalR: Stopping the monitoring of the keep alive.
JQMIGRATE: Migrate is installed, version 3.0.0
SignalR: Client subscribed to hub 'prismhub'.
SignalR: Negotiating with '/signalr/negotiate?clientProtocol=1.5&connectionData=%5B%7B%22name%22%3A%22prismhub%22%7D%5D'.
SignalR: serverSentEvents transport starting.
SignalR: This browser doesn't support SSE.
SignalR: serverSentEvents transport failed to connect. Attempting to fall back.
SignalR: foreverFrame transport starting.
SignalR: Binding to iframe's load event.
SignalR: Iframe transport started.
SignalR: foreverFrame transport connected. Initiating start request.
SignalR: The start request succeeded. Transitioning to the connected state.
SignalR: Now monitoring keep alive with a warning timeout of 13333.333333333332, keep alive timeout of 20000 and disconnecting timeout of 30000
Connected to signalR hub
SignalR: foreverFrame transport timed out when trying to connect.
**SignalR: Triggering client hub event 'sendUpdatedChange' on hub 'prismHub'.**
The notifications don't appear to be working in Chrome. In the log, I can see that SignalR is pushing out the notifications:
SignalR: Window unloading, stopping the connection.
SignalR: Stopping connection.
SignalR: EventSource calling close().
SignalR: Fired ajax abort async = false.
SignalR: Stopping the monitoring of the keep alive.
JQMIGRATE: Migrate is installed, version 3.0.0
SignalR: Client subscribed to hub 'prismhub'.
SignalR: Negotiating with '/signalr/negotiate?clientProtocol=1.5&connectionData=%5B%7B%22name%22%3A%22prismhub%22%7D%5D'.
SignalR: serverSentEvents transport starting.
SignalR: Attempting to connect to SSE endpoint 'http://localhost:61159/signalr/connect?transport=serverSentEvents&clientPro…FNE6BKzqphux4&connectionData=%5B%7B%22name%22%3A%22prismhub%22%7D%5D&tid=9'.
SignalR: EventSource connected.
SignalR: serverSentEvents transport connected. Initiating start request.
SignalR: The start request succeeded. Transitioning to the connected state.
SignalR: Now monitoring keep alive with a warning timeout of 13333.333333333332, keep alive timeout of 20000 and disconnecting timeout of 30000
Connected to signalR hub
**SignalR: Triggering client hub event 'sendUpdatedChange' on hub 'prismHub'.
SignalR: Triggering client hub event 'sendUpdatedChange' on hub 'prismHub'.
SignalR: Triggering client hub event 'sendUpdatedChange' on hub 'prismHub'.**
But the data in my view is not changing (as it does in Internet Explorer). This problem occasionally occurs in IE. Also, refreshing a page appears to break the hub connection. From IE console:
HTML1300: Navigation occurred.
File: AllChanges
JQMIGRATE: Migrate is installed, version 3.0.0
SignalR: Client subscribed to hub 'prismhub'.
SignalR: Negotiating with '/signalr/negotiate?clientProtocol=1.5&connectionData=%5B%7B%22name%22%3A%22prismhub%22%7D%5D'.
SignalR: serverSentEvents transport starting.
SignalR: This browser doesn't support SSE.
SignalR: serverSentEvents transport failed to connect. Attempting to fall back.
SignalR: foreverFrame transport starting.
SignalR: Binding to iframe's load event.
SignalR: Iframe transport started.
SignalR: foreverFrame transport connected. Initiating start request.
SignalR: The start request succeeded. Transitioning to the connected state.
SignalR: Now monitoring keep alive with a warning timeout of 13333.333333333332, keep alive timeout of 20000 and disconnecting timeout of 30000
Connected to signalR hub
SignalR: foreverFrame transport timed out when trying to connect.
It is worth noting that these requests make an ajax call to the controller that hits the database with a linq query, returning a list of data:
View JS
$(document).ready(function () {
FetchChanges();
notifications.client.sendUpdatedChange = function () { FetchChanges(); };
}
function FetchChanges() {
var model = $('#divChanges');
$.ajax({
url: '/Changes/AllChangesItems',
contentType: 'application/html ; charset:utf-8',
type: 'GET',
dataType: 'html',
})
.done(function (result) {
model.empty().append(result);
})
}
Controller Action
public ActionResult AllChangesItems()
{
var username = CurrentUser().UserName;
var changes = db.Changes;
List<ChangeListingViewModel> vm = new List<ChangeListingViewModel>();
foreach (var c in changes)
{
vm.Add(new ChangeListingViewModel(c));
}
return PartialView("_ActiveItems", vm.ToList());
}
where ChangeListingViewModel contains two linq queries fetching the child rows (can provide code if revelant):
However, a 'simpler' query seems to work fine in IE and Chrome, i.e. the push notifications trigger JS functions that update the view:
public void PinChange(int id)
{
CurrentUserDetails().User.PinnedChanges.Add(db.Changes.Find(id));
db.SaveChanges();
PrismHub.NotifyPinnedChange();
}
My first thought is that some kind of timeout is occurring, but I'm not sure why that would differ between browsers. Any suggestions would be greatly appreciated.
EDIT: Updated with Hub info EDIT 2: Updated hub method to be consistent with other snippets.
Here is the snippet of my hub class:
Hub
[HubName("prismHub")]
public class PrismHub : Hub
{
private static IHubContext context = GlobalHost.ConnectionManager.GetHubContext<PrismHub>();
[HubMethodName("notifyUpdatedChange")]
public static void NotifyUpdatedChange()
{
context.Clients.All.sendUpdatedChange();
}
}
Accidentally stumbled upon the solution. After several weeks of searching I encountered this post: signalr client hub events not being triggered within a jquery .ready() method
This issue was solved by addressing this piece of JS in the view:
$(document).ready(function () {
FetchChanges();
notifications.client.sendUpdatedChange = function () { FetchChanges(); };
}
Moving the SignalR function mapping outside of the $(document).ready() resolved it:
$(document).ready(function () {
FetchChanges();
}
notifications.client.sendUpdatedChange = function () { FetchChanges(); };
I have yet to discover why this is a problem, but I'm happy to have found a solution.
这篇关于SignalR更新无法正常使用Chrome的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!