How do I configure IIS 7.5 for SSE (Server Sent Events) and SignalR

ぐ巨炮叔叔 提交于 2019-12-12 07:57:34

问题


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.


回答1:


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)




回答2:


What might be happening that the server is compressing the dynamic content generated before sending it to client. Add this in your web.config to fix

   <location path="signalr">
    <system.webServer>
      <urlCompression doDynamicCompression="false"/>
    </system.webServer>
  </location>


来源:https://stackoverflow.com/questions/12177737/how-do-i-configure-iis-7-5-for-sse-server-sent-events-and-signalr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!