我们使用信号 r 来驱动我们的前端进行更新,它一直在 100% 工作,直到我们升级到 .net core 2.2
请参阅下面的启动,这些方法确实被调用并且正常的后端调用可以正常工作,但是只要 Signal r 尝试从前端连接,我就会收到一个 cors 错误。
我试图让所有通过cors,但这也没有用。
protected IServiceProvider ConfigureServicesImplementation(IServiceCollection services)
{
services.Configure<DatabaseConfiguration>(Configuration.GetSection(DatabaseConfigurationName));
services.Configure<TokenProviderConfiguration>(Configuration.GetSection(TokenProviderConfigurationName));
services.AddOptions();
services.AddCors();
services.AddAutoMapper();
services.AddAutofac();
services.AddSingleton<IActionContextAccessor, ActionContextAccessor>();
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddScoped<DatabaseMigrator>();
services.AddScoped<AdminTenantDbInitialiser>();
services.AddScoped<TenantDbInitialiser>();
services.AddScoped<HubBase>();
services.AddScoped<HubService>();
services.AddSignalR()
.AddJsonProtocol(options =>
{
options.PayloadSerializerSettings.Converters.Add(new StringEnumConverter
{
});
});
至于从前端连接,请参见下面的代码。
public startHubConnection(): void {
if (!this.hubConnection) {
const currentUser = this.authenticationService.getCurrentUser();
this.hubConnection = new HubConnectionBuilder().withUrl(this.url + '/globalhub?Authorization=Bearer ' + currentUser.accessToken).build();
}
this.hubConnection
.start()
.then(() => {
this.isHubConnected = true;
if (this.firstRun) {
this.firstRun = false;
this.manageHubConnections();
}
人到中年有点甜
湖上湖
相关分类