如何为SSE(服务器发送事件)和SignalR配置IIS 7.5 [英] How do I configure IIS 7.5 for SSE (Server Sent Events) and SignalR
问题描述
我已经测试了我的Asp.NET MVC应用程序以运行SignalR,并且使用Visual Studio 2012,IIS Express(Microsoft-IIS/8.0)和Chrome浏览器通过serverSentEvents连接正确处理了text/event-stream
MIME.
现在我要部署到生产环境(IIS 7.5,.NET Framework 4.5,Windows Server 2008R2),我注意到SignalR总是回退到LongPolling传输,因为signalr/connect?transport=serverSentEvents etc
超时.
是否可以配置Microsoft-IIS/7.5以使ServerSentEvents正常工作?还是只有在8.0+上才有可能?
当我尝试直接访问网址时
'http://my.webapp.com/MyHub/signalr/connect?transport=serverSentEvents&connectionId=624849a4-45c6-458b-b6d0-f7cb023ab226&connectionData=%5B%7B%22name%22%3A%22myHub%22%7D%5D&tid=2'
我正在获取一个包含看起来像SSE数据包的文件:
data: initialized
id: 14476
data: {"MessageId":"14476","Messages":[],"Disconnect":false,"TimedOut":false,"TransportData":{}}
所以我不确定为什么超时会达到要求.
结果证明我不需要特定配置-SignalR退回longPolling取决于事实是我的服务器显然是在代理后面.
要对此进行测试,我建议尝试使用本地主机作为Web地址连接到服务器上的中心服务器-在我的情况下,传输已正确设置为serverSentEvents(使用Chrome时)或foreverFrame(使用IE时)>
向用户dfowler信用以获取提示(更多此处)
I have tested my Asp.NET MVC application to run SignalR and it properly handles the text/event-stream
MIME with a serverSentEvents connection, using Visual Studio 2012, IIS Express (Microsoft-IIS/8.0) and Chrome.
Now that I am deploying to production environment (IIS 7.5, .NET Framework 4.5, Windows Server 2008R2), I've noticed that SignalR always falls back to LongPolling transport, since the signalr/connect?transport=serverSentEvents etc
times out.
Is there a way to configure Microsoft-IIS/7.5 to make ServerSentEvents work? Or is this possible only on 8.0+?
When I try to directly access the url
'http://my.webapp.com/MyHub/signalr/connect?transport=serverSentEvents&connectionId=624849a4-45c6-458b-b6d0-f7cb023ab226&connectionData=%5B%7B%22name%22%3A%22myHub%22%7D%5D&tid=2'
I am getting a file which contains what looks like a SSE data packet:
data: initialized
id: 14476
data: {"MessageId":"14476","Messages":[],"Disconnect":false,"TimedOut":false,"TransportData":{}}
so I am not sure why the timeout is hitting the request.
Turns out that no specific configuration was required in my case - SignalR falling back to longPolling depended on the fact that my server is evidently behind a proxy.
To test this, I suggest to try the connection to the hub server on server using localhost as web address - in my case the transport is correctly set up as serverSentEvents (when using Chrome) or foreverFrame (when using IE)
Credit to user dfowler for the heads up (more here)
这篇关于如何为SSE(服务器发送事件)和SignalR配置IIS 7.5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!