Last week, Microsoft released the first .NET 9 Release Candidate. This is the first Go-live version of the new framework, expected to be released later this year. Among other features, it consolidates significant updates to ASP.NET Core, including keep-alive timeout for WebSockets, support for Keyed DI services in middleware, and improvements to SignalR distributed tracing.
One of the most important features of this release is the addition of keep-alive timeouts in the WebSockets middleware configuration. The new APIs on ClientWebSocketOptions
and WebSocketCreationOptions
allow for sending WebSocket pings, aborting the connection ( and throwing an exception) if the client does not respond within the specified timeout period. This is a fix for an issue raised in 2021 by GitHub user @bjornen77:
Today, the
ClientWebSocket
is closed when the TCP Retransmission times out (if the connection to the server drops for some reason). This timeout seems to be different on Windows and Linux. By default, on Windows it takes about 21 seconds and on Linux it takes about 15 minutes before the WebSocket is closed. It would be good if we could have a separate Timeout setting, so that we get the same behavior regardless of the platform. And also that this could be configured by the application without having to modify the TCP Timeout settings in the OS.
Another interesting update in this release is the support for Keyed DI services in both the constructor and the Invoke
/ InvokeAsync
methods. "Keyed DI" refers to a mechanism for registering and retrieving Dependency Injection (DI) services using keys. Once a service is registered with a key, this key can be used for accessing its associated service later. The example below shows the use of keyed services in the new release:
var app = builder.Build();
app.UseMiddleware<MyMiddleware>();
app.Run();
internal class MyMiddleware
{
private readonly RequestDelegate _next;
public MyMiddleware(RequestDelegate next, [FromKeyedServices("test")] MySingletonClass service)
{
_next = next;
}
public Task Invoke(HttpContext context, [FromKeyedServices("test2")] MyScopedClass scopedService) => _next(context);
}
InputNumber
component and Linux (Ubuntu- and Fedora-based distros) support for the ASP.NET Core HTTPS development certificate to be configured as a trusted certificate for Chromium and Mozilla browsers, as well as for use with .NET APIs.