是的,ASP.NET Core的Kestrel服务器在启动时可以配置空闲超时时间。可以通过在ConfigureServices方法中设置KestrelServerOptions的AddServerHeader属性来实现。
以下是一个示例代码:
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.Configure(options =>
{
options.Limits.KeepAliveTimeout = TimeSpan.FromSeconds(30); // 设置空闲超时时间为30秒
});
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
// ...
}
}
在上述示例中,将KestrelServerOptions的KeepAliveTimeout属性设置为TimeSpan.FromSeconds(30),表示空闲超时时间为30秒。您可以根据需要更改超时时间。
请确保在ConfigureServices方法中添加对Microsoft.AspNetCore.Server.Kestrel.Core包的引用。