环境:
问题:
No Connection with that ID
。但是有时它会在4毫秒内连接,这很奇怪(重新连接之间有10秒的延迟)。其他信息:
www.myapp.domain.com:88/application
,信号中心Hub:www.myapp.domain.com:88/application/appHub
),但这似乎无关紧要,因为当我仅使用内部IP时也会出现问题。.Net Core:
public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddCors(options => options.AddPolicy("CorsPolicy", builder =>
{
builder.AllowAnyHeader()
.AllowAnyMethod()
.AllowAnyOrigin()
.AllowCredentials();
}));
services.AddSignalR(hubOptions =>
{
hubOptions.EnableDetailedErrors = true;
hubOptions.KeepAliveInterval = TimeSpan.FromSeconds(10);
hubOptions.HandshakeTimeout = TimeSpan.FromSeconds(5);
});
services.AddMvc(options =>
{
options.Filters.Add(new ProducesAttribute("application/json"));
})
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
.AddControllersAsServices();
services.AddAuthentication(Configuration);
services.AddAuthorizationPolicies();
return ServiceProviderFactory.CreateAutofacServiceProvider(services, Configuration);
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseHsts();
}
app.UseCors("CorsPolicy");
app.UseAuthentication();
app.UseExceptionHandler(env);
app.UseWebSockets();
app.UseHubs();
app.UseMvc();
}
JS:
private buildConnection() {
const connectionBuilder = new HubConnectionBuilder();
this.hubConnection = connectionBuilder
.withUrl(environment.hubUrl, { accessTokenFactory: () => this.accessToken() })
.configureLogging(LogLevel.Trace)
.build();
}