SignalR - how to disable WebSockets (but keep other transports active)?

℡╲_俬逩灬. 提交于 2021-02-08 09:05:53

问题


In both a C# client and Web Client - how do I tell signalR - "Try everything but websockets"?

I have the following in my web code:

 window.hubReady = $.connection.hub.start({ transport: 'longPolling' });

But this is just javascript and longpolling; I'm looking for the configuration for both JS and C# clients to only remove websockets as a transport. How can this be done?


回答1:


On the server:

 public class Startup    
 {
     public void Configuration(IAppBuilder app)
     {
         DisableWebSockets(GlobalHost.DependencyResolver);

         HubConfiguration hubConfiguration = new HubConfiguration();
         hubConfiguration.EnableDetailedErrors = true;
         app.MapSignalR(hubConfiguration);
     }

     public static void DisableWebSockets(IDependencyResolver resolver)
     {
         var manager = resolver.Resolve<ITransportManager() as TransportManager;
         manager.Remove("webSockets");
     }
 }

On the client:

$.connection.hub.start({ transport: ['serverSentEvents', 'foreverFrame', 'longPolling'] }).done(function () {...}

Edit - adding bracket



来源:https://stackoverflow.com/questions/42738840/signalr-how-to-disable-websockets-but-keep-other-transports-active

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