小编Jay*_* TM的帖子

SignalR 适用于 Angular 7 的 ASP.NET MVC(不是 ASP.NET 核心)

您好,我尝试将 signalR 与 asp.net mvc 5 和 Angular 7 一起使用,但无法在集线器之间建立连接

这是我的代码

角7

import { Component, OnInit } from '@angular/core';
import { HubConnection, HubConnectionBuilder } from '@aspnet/signalr';
import * as $ from '@aspnet/signalr'

@Component({
selector: 'app-admin-dashboard',
templateUrl: './admin-dashboard.component.html',
styleUrls: ['./admin-dashboard.component.scss']
})

export class AdminDashboardComponent implements OnInit {
private _hubConnection: HubConnection;
constructor() {
this._hubConnection = new HubConnectionBuilder()
  .withUrl("http://localhost:4200/hub/cashnet", {
    skipNegotiation: true,
    transport: $.HttpTransportType.WebSockets
  })
  .configureLogging($.LogLevel.Information)
  .build();

this._hubConnection.start().then(() => {
  console.log('Hub connection started');
}).catch(err => {
  console.log('Error while establishing connection :(')
});

this._hubConnection.on('sendMessage', …
Run Code Online (Sandbox Code Playgroud)

signalr signalr-hub asp.net-mvc-5 angular7

4
推荐指数
1
解决办法
3840
查看次数

标签 统计

angular7 ×1

asp.net-mvc-5 ×1

signalr ×1

signalr-hub ×1