微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

获取ASP .NET Core 3.1 / Kestrel中的连接数

如何解决获取ASP .NET Core 3.1 / Kestrel中的连接数

我使用以下方法限制与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 举报,一经查实,本站将立刻删除。