Im trying CORS.
SignalR server is created in ASP.Net using this link . And im trying to access the Hub from ASP.Net Core client application using "@aspnet/signalr-client". My question is
- Is this possible?.
- If possible, how the "/signalr/hub" js will be used in asp.net core.
I tried this and got this error when i call .start();
Error while establishing connection - "SyntaxError: Unexpected end of JSON input
at JSON.parse (<anonymous>)
at HttpConnection.<anonymous> (HttpConnection.js:41)
at Generator.next (<anonymous>)
at fulfilled (HttpConnection.js:6)
at ZoneDelegate.invoke (vendor.js?v=RCvRrqPvM2Kc5BlkEQ045FeXR6gPMRIwfn51ludN14I:86198)
at Object.onInvoke (vendor.js?v=RCvRrqPvM2Kc5BlkEQ045FeXR6gPMRIwfn51ludN14I:15003)
at ZoneDelegate.invoke (vendor.js?v=RCvRrqPvM2Kc5BlkEQ045FeXR6gPMRIwfn51ludN14I:86197)
at Zone.run (vendor.js?v=RCvRrqPvM2Kc5BlkEQ045FeXR6gPMRIwfn51ludN14I:85948)
at vendor.js?v=RCvRrqPvM2Kc5BlkEQ045FeXR6gPMRIwfn51ludN14I:86625
at ZoneDelegate.invokeTask (vendor.js?v=RCvRrqPvM2Kc5BlkEQ045FeXR6gPMRIwfn51ludN14I:86231)"
im trying to connect the Hub from type script code. if i use normal jquery in index.chtml then it gets connected. Is this possible from type script
my index.chtml code
@section scripts { <script src="~/dist/main-client.js" asp-append-version="true"></script> <!--Reference the autogenerated SignalR hub script. --> <script src="http://localhost:52527/Scripts/jquery-1.10.2.min.js"></script> <script src="http://localhost:52527/Scripts/jquery.signalR-2.0.3.min.js"></script> <script src="http://localhost:52527/signalr/hubs"></script> <script> $(function () { $.connection.hub.url = "http://localhost:52527/signalr/ChatHub" // Start the connection. try { $.connection.hub.start({ transport: 'longPolling' }).done(function () { console.log('Hub connection started'); }); } catch (error) { console.log('Error while establishing connection', error);} }); </script>}
my home.component.ts code
ngOnInit() { this._hubConnection = new HubConnection('http://localhost:52527/chatHub', { transport: TransportType.LongPolling, logging: LogLevel.Information }); console.log(this._hubConnection); this._hubConnection.on('Send', (data: any) => { const received = `Received: ${data}`; this.messages.push(received); //}); this._hubConnection.start() .then(() => { console.log('Hub connection started') }) .catch((error) => { console.log('Error while establishing connection' , error) }); }
Thanks in advance.