如何检测Kestrel

问题描述 投票:0回答:1
dbug: Microsoft.AspNetCore.Server.Kestrel.Connections[39] Connection id "0HMCEE5LHGSKR" accepted. dbug: Microsoft.AspNetCore.Server.Kestrel.Connections[1] Connection id "0HMCEE5LHGSKR" started.

当我通过单击“关闭窗口”按钮(x)关闭客户端时,我会看到以下内容:

dbug: Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets[19] Connection id "0HMCEE5LHGSKR" reset. dbug: Microsoft.AspNetCore.Server.Kestrel.Http2[48] Connection id "0HMCEE5LHGSKR" is closed. The last processed stream ID was 1. dbug: Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets[7] Connection id "0HMCEE5LHGSKR" sending FIN because: "The client closed the connection." dbug: Microsoft.AspNetCore.Server.Kestrel.Connections[2] Connection id "0HMCEE5LHGSKR" stopped.
使用listeroptions.useconnectionlogging(listoptions)扩展方法的选项未提供我可以找到的回调选项。显然,在默认中间件中,该事件正在捕获,但我找不到该选项的路径。  Microsoft.aspnetcore.server.kestrel名称空间的检查(我可以找到)如何到达Microsoft.aspnetcore.server.kestrel.connections.connections或Microsoft.aspnetcore.keserver.keserver.kestrel.kestrel.transport.transport.sockets.sockets data.sockets数据。
我正在使用Visual Studio 2022,.NET 6,C#10和GRPC。  这是我当前的Kestrel配置:

// Configure Kestrel, the .NET Core web server. var hostBuilder = webHostBuilder.ConfigureKestrel (kestrelServerOptions => { kestrelServerOptions.ConfigureHttpsDefaults (httpsConnectionAdapterOptions => httpsConnectionAdapterOptions.SslProtocols = SslProtocols.Tls12); // Read in the X.509 certificate file. var certPath = Path.Combine (builder.Environment.ContentRootPath, "Certs", $"{environment}.pfx"); kestrelServerOptions.ConfigureEndpointDefaults (listenOptions => { _ = listenOptions.UseHttps (certPath, password); logger.Debug ($"Using {certPath} as the cert file."); logger.Debug ("Configuring host to use HTTP/2 protocol."); listenOptions.Protocols = HttpProtocols.Http2; }); logger.Debug ("Reading config values for the server name and port."); // Get the host name and port number to bind the service to. var port = builder.Configuration.GetValue<int> ("AppSettings:OperationsServerPort"); var address = IPAddress.Parse ("0.0.0.0"); if (address != null) { logger.Debug ($"Host will listen at https://{address}:{port}"); kestrelServerOptions.Listen (address, port); } else { logger.Error ("DNS address for service host cannot be determined! Exiting..."); Environment.Exit (-1); } });
任何线索,指导,例子将不胜感激!
    

well,我可能会迟到游戏来理解所有ASP.NET核心配置,但是要陷阱连接即将到来很简单...将中间件委托添加到听众中是全部...

var ipEndpoint = new IPEndPoint (address, port);

kestrelServerOptions.Listen (ipEndpoint, action => action.Use (async (context, next) => {

    Console.WriteLine ($"INTERNAL ---------------- New Connection: {context.ConnectionId}");

    await next.Invoke ();

    Console.WriteLine ($"INTERNAL ---------------- Connection terminated: {context.ConnectionId}");
}));

该摘要通过添加中间件代表修改了我的原始帖子。可以在此处找到让我超越logjam的所需阅读:

https://learn.microsoft.com/en-us/aspnet/core/fundamentals/middleware/?view =aspnetcore-5.0
c# asp.net-core grpc kestrel
1个回答
2
投票
我希望这对某人有帮助!

对于ASP.NET CORE 6.0,tectecting连接闭合已略有更改。我的工作如下:
var builder = WebApplication.CreateBuilder(args);
builder.WebHost.ConfigureKestrel((context, serverOptions) =>
{
    serverOptions.Listen(IPAddress.Parse("192.168.150.122"), 80, (ListenOptions listenOptions) =>
    {
        listenOptions.Use((ConnectionDelegate cd) =>
        {
            return (ConnectionContext cc) =>
            {
                Console.WriteLine($"[{cc.ConnectionId}] connected from: {cc.RemoteEndPoint}");
                var r = cd(cc); // returns a task processing the connection.
                Task.Run(async () =>
                {
                    await r.WaitAsync(Timeout.InfiniteTimeSpan); // effectively waits until processing is completed.
                    Console.WriteLine($"[{cc.ConnectionId}] disconnected from: {cc.RemoteEndPoint}");
                });
                return r;
            };
        });
    });
});
var app = builder.Build();
app.MapGet("/", () => "Hello World!");
app.Run();

工作量为8.0。

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.