- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我用 Angular6 开发了一个项目。需要开发实时聊天部分。为此,我在我的 asp.net core Web Api 项目中使用 SignalR。现在我想在我的 Angular 项目中使用此 Web Api 引用。
我正在使用this链接。
但是在 App.Component.ts 中提供 Web Api url 时,我收到以下错误:
Constructor of class 'HubConnection' is private and only accessible within the class declaration.
应用程序组件.ts:
import { HubConnection } from '@aspnet/signalr';
import { Message } from 'primeng/api';
export class AppComponent implements OnInit {
public _hubConnection: HubConnection;
msgs: Message[] = [];
constructor() {
}
ngOnInit() {
this._hubConnection = new HubConnection('http://localhost:1874/notify'); // getting error on this line.
编辑:尝试了以下代码:-
修改App.Component.ts:
import { HubConnection } from '@aspnet/signalr';
import * as signalR from '@aspnet/signalr';
import { Message } from 'primeng/api';
export class AppComponent implements OnInit {
public _hubConnection: HubConnection;
msgs: Message[] = [];
constructor() {
}
ngOnInit() {
this._hubConnection = new signalR.HubConnectionBuilder()
.withUrl('http://localhost:1874/notify')
.configureLogging(signalR.LogLevel.Information)
.build();
错误:
Failed to load http://localhost:1874/notify/negotiate: Response to preflight request doesn't pass access control check: The value of the 'Access-Control-Allow-Credentials' header in the response is '' which must be 'true' when the request's credentials mode is 'include'. Origin 'http://localhost:4200' is therefore not allowed access. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.
最佳答案
他们更改了 SignalR 客户端 HubConnection
的构造函数,不再允许您在客户端构造函数中传递路由,并将 HubConnection
构造函数设为私有(private)以强制执行更改。相反,您需要使用 HubConnectionBuilder
,如下所示:
new HubConnectionBuilder().withUrl("/YOURROUTEHERE").build();
您需要在 header 中导入 HubConnectionBuilder,如下所示:
从 '@aspnet/signalr' 导入 { HubConnection, HubConnectionBuilder };
如果有帮助,我还刚刚发布了 @aspnet/signalr 1.0.2、RxJs 5.5.6 和 Angular 6 的 RxSignalR 示例的更新。查看 ReactiveChat component举个例子。
关于signalr - 角度 : Unable to pass API url in SignalR HubConnection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51112154/
我正在使用 SignalR 版本 2.2.0。使用下面的代码,我得到一个异常,指出 $ 没有定义 hubConnection。我知道我的脚本路径是正确的,因为我可以在信号脚本中设置断点并查看它们是否被
我的 SignalR 项目遇到了问题。我创建了一个控制台来运行 SignalR,然后尝试在我的网站上使用它(目前都以 localhost 模式运行) SignalRSSelfHost using Sy
我用以下代码构建了一个通知系统: class SignalRClient { HubConnection hubconn; IHubProxy proxy; public Si
我正在尝试在基于 an example over here 的 ASP.NET MVC 4 应用程序中实现聊天模块。由于这个没有使用最新的 SignalR 版本 (0.5.3),我必须调整代码才能使其
两者有什么区别 this.hubConnection = new signalR.HubConnectionBuilder() .withUrl(environment.API_URL + "in
在 AspNet SignalR 客户端中,是否需要处理 HubConnection 操作? 从我所看到的来看,这似乎需要一些时间...... 最佳答案 如果您调用 Stop(),则不需要。 参见ht
两者有什么区别 this.hubConnection = new signalR.HubConnectionBuilder() .withUrl(environment.API_URL + "in
大家好,我正在致力于使用基于 example over here 的 AngularJS 实现 SignalR 股票行情自动收录器。但是我在连接到信号器时遇到错误,如下所示 TypeError: $.
嗨,我是 android 开发的新手,我想编写一个使用 signalR java 客户端的应用程序。在第一步中,我做了 this 的答案这是我的客户端代码: Platform.loadPlatform
根据我发现的一个例子,http://weblog.west-wind.com/posts/2013/Sep/04/SelfHosting-SignalR-in-a-Windows-Service ,我
我有一个带有 signalR 的 ASPNet.Core WebApi。我有使用 webAPI 的 angular 应用程序,我想用 Blazor Webassembly 应用程序替换它。我在 Bla
我在 Android 中从事 SignalR 实现工作。在第一步中,它很容易连接。重新打开应用程序后,它因记录错误而崩溃。集线器连接已连接 Platform.loadPlatformComponen
我们已经编写了一个原型(prototype)来测试 SignalR 的性能,以检查我们是否可以将它用于我们的软件。在该原型(prototype)中,我们测试了两者,通过 PersistentConne
我正在尝试使用 powershell 脚本连接到 SignalR 集线器。我是 Powershell 的新手,所以请原谅任何菜鸟错误。 我已经设置了一个最小的 not 工作示例来说明我在这里尝试过的内
我正在查看 unit tests对于 SignalR 并注意到其中一项测试使用 Moq 创建模拟 HubConnection: [Fact] public void HubCallbackCleare
我已在无服务器模式下创建了 Azure SignalR 服务。我在 Azure 函数应用程序中有一套函数来管理必须包含组的聊天服务。发布 Function App 时,我将 AzureSignalRC
我正在尝试将参数添加到信号器的连接中。 我正在使用 Builder 创建我的客户端连接并启动它: var connection = new HubConnectionBuilder()
我正在尝试实现一个 Angular 和信号器项目。我从 Medium 获取样本 我已经安装了所有必要的包,并且在 app.component.ts 中有以下代码: import { Component
我的 Blazor WebAssembly 应用程序中有一个 SignalR HubConnection,虽然它大部分时间都在工作,但如果我重新加载页面(通过浏览器重新加载),那么我经常会在控制台并且
我用 Angular6 开发了一个项目。需要开发实时聊天部分。为此,我在我的 asp.net core Web Api 项目中使用 SignalR。现在我想在我的 Angular 项目中使用此 Web
我是一名优秀的程序员,十分优秀!