How to use cross-domain connections (CORS - Access Control Allow Origin) with SignalR

前端 未结 6 1054
有刺的猬
有刺的猬 2020-12-05 03:08

Using persistent connections and an ASP.NET JavaScript client, I am trying to connect to a sub-domain not the same as the one the page was served from.

ASP.Net Page

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-05 03:36

    What really have solved my issue was:

    1 - Add this to global.asax:

    RouteTable.Routes.MapHubs(new HubConfiguration() { 
        EnableCrossDomain = true 
    });
    

    2- Set up the web.config of my web project to enable the cross-domain:

    
        
            
                
                
            
        
    
    

    3- Then I change the implementation on my html, changing the $.connection() to as follow:

    var connection = $.hubConnection('http://localhost.my:8081/signalr');
    var chatHubProxy = connection.createHubProxy('chatHub');
    

    Versions I'm using:

    • signalR-1.1.0

    • jquery.signalR-1.1.3.js

    • dot.net 4.0

提交回复
热议问题