Angular IIS上的信号器握手超时
环境:Angular IIS上的信号器握手超时,angular,asp.net-core,iis-7,signalr,asp.net-core-2.1,Angular,Asp.net Core,Iis 7,Signalr,Asp.net Core 2.1,环境: public IServiceProvider ConfigureServices(IServiceCollection services) { services.AddCors(options => options.AddPolicy("CorsPolicy", builder => { builder.AllowAnyHeader() .AllowAnyMethod()
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();
}
- Windows 7 Home上的IIS 7.0
- 用asp.net core 2.1编写的Web服务
- WebClient是用Angular编写的
- 最新的信号器库(.NET核心和JS)
private buildConnection() {
const connectionBuilder = new HubConnectionBuilder();
this.hubConnection = connectionBuilder
.withUrl(environment.hubUrl, { accessTokenFactory: () => this.accessToken() })
.configureLogging(LogLevel.Trace)
.build();
}
- 由于15秒超时,握手请求失败。服务器的唯一响应是
。但有时它会在4ms内连接,这是完全奇怪的(重新连接之间有10s的延迟)没有与该ID的连接
private buildConnection() {
const connectionBuilder = new HubConnectionBuilder();
this.hubConnection = connectionBuilder
.withUrl(environment.hubUrl, { accessTokenFactory: () => this.accessToken() })
.configureLogging(LogLevel.Trace)
.build();
}
- IIS也可以从外部访问(比方说
,signer Hub:www.myapp.domain.com:88/application
),但这似乎无关紧要,因为当我只使用内部IP时也会出现问题www.myapp.domain.com:88/application/appHub
- 在IIS上,任何其他请求都能正确快速地工作,唯一的问题是信号器连接
- 由于有回退,它使用SSE
- 在开发环境(kestrel)上,一切正常
- 所有防火墙等均已关闭
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();
}
(敏感数据被删除)
服务器上有日志吗?您是否尝试了
usesigner
而不是UseWebsockets
?老实说,日志中没有什么有趣的内容。今天,我尝试将其配置为IIS作为反向代理,但仍然存在相同的问题。但如果我直接连接到红隼,它会工作。将IIS 10与WebSocket一起使用也会有所帮助。