问题描述
我使用以下方法限制与Kestrel托管的Web应用程序的并发连接数:
webBuilder.UseKestrel((context,options) =>
{
options.Configure(context.Configuration.GetSection("Kestrel"));
options.AddServerHeader = false;
// get limits
var maxConnections = context.Configuration.GetValue<int>("Kestrel:Limits:MaxConcurrentConnections");
var maxUpgradedConnections = context.Configuration.GetValue<int>("Kestrel:Limits:MaxConcurrentUpgradedConnections");
options.Limits.MaxConcurrentConnections = maxConnections;
options.Limits.MaxConcurrentUpgradedConnections = maxUpgradedConnections;
...
}
当接收到新请求时,我想检查服务器当前的连接数,并通过显示有关连接限制的错误消息来执行正常拒绝。我尝试过的一种方法是添加用于检查的中间件,如下所示:
public void Configure(IApplicationBuilder app)
{
app.Use(async (context,next) =>
{
// Insert limit check here
// Call the next delegate/middleware in the pipeline
await next();
});
}
问题是我还没有找到一种方法来获取Kestrel中的连接数。有人知道如何获得它吗?还是这甚至是可行的方法?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)