SignalR - Forever Frame in IE stops working after

2019-04-29 13:27发布

问题:

I am using SignalR in IE9 and, unfortunately, it has to degrade to using the forever frame connection.

I have spent some time looking at this with the Developer Tools in IE. I can see the callbacks loading into the dynamically inserted IFrame, and they call the receive function in the SignalR plugin. However after about 20/30 of these it just stops responding - I can no longer call client script from the server.

I'm guessing that the IFrame load is finally timing out, but there appear to be no events raised for this, so I cannot force a reconnect.

Has anyone managed to get a robust SignalR connection working in IE?

Thanks :)

回答1:

We had an issue where the Javascript on a website would stop working, specifically we noted this in that Ajax calls would not work. After some investigation we found that SignalR was the reason for the crash, and we found this post about Forever Frames. We tried removing Forever Frames support in SignalR with the following code in the clients JavaScript:

$.connection.hub.start({ transport: ['webSockets', 'serverSentEvents', 'longPolling'] });

Thus only supporting 'webSockets', 'serverSentEvents', 'longPolling'.



回答2:

According to this Github issue this was fixed in jQuery 1.10.1.

The problem was introduced in 1.9.x and fixed on 1.10.1.

Running with JQuery 1.8.1 it seems to work too.

Solution: Update jQuery



回答3:

Whenever I saw this happening, I actually had rogue, zombie IE9 processes running in the background. They didn't even have a window associated with them. So, I would go and kill those zombies off and relaunch a new instance of IE and not have a problem for a long time until whatever anamoly causes the issue happened again.

Sounds crazy I know, but I spent a long time explaining to David Fowler the symptoms of the problem and how I could never see any reason for the iFrame to magically stop firing the event to have the transport know to start the next iFrame session. The SignalR messages themselves always terminated the logical message stream properly, the onreadystatechange event would simply stop firing.



回答4:

Put this in document ready event and all of your iframe problems would be solved:

$.connection.hub.start({ transport: ['webSockets', 'serverSentEvents', 'longPolling'] });