Microsoft has released .NET 9, which contains features regarding ASP.NET Core 9. These features improve performance, streamline development, and extend the framework’s capabilities. This latest release focuses on optimizing static asset handling, refining Blazor's component interaction, enhancing SignalR's observability and performance, and streamlining API documentation through built-in OpenAPI support.
Microsoft has improved Blazor with several updates to enhance component interaction and rendering capabilities. One of them is a new runtime API that enables developers to query component states. This functionality allows them to determine the execution status of a component and whether it is running interactively. As a result, this aids in optimizing performance and troubleshooting issues more effectively. Additionally, the update introduces the [ExcludeFromInteractiveRouting]
attribute, which facilitates static server-side rendering (SSR) for specific pages. This feature is particularly beneficial for pages that require traditional HTTP cycles instead of interactive rendering.
The next addition is MapStaticAssets
, designed to optimize the delivery of static resources. This feature automates tasks like compression, caching, and versioning, which previously required manual configuration. It integrates build and publish-time metadata to better serve static assets, supporting frameworks such as Blazor, Razor Pages, and MVC. While MapStaticAssets works well for assets managed by the app, UseStaticFiles
is still available for handling external or dynamic resources. Developers can implement MapStaticAssets with ease:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRazorPages();
var app = builder.Build();
app.UseHttpsRedirection();
app.MapStaticAssets();
SignalR now supports polymorphic hub method arguments, enabling methods to accept base classes for dynamically handling derived types. In addition, activity tracking in SignalR has been improved with detailed event generation for each hub method. Furthermore, support for trimming and Native AOT (Ahead-of-Time) compilation has been introduced, which decreases application size and enhances performance for both clients and servers.
Moreover, Minimal APIs are enhanced by new tools designed for error handling. Developers can now utilize TypedResults
to return strongly typed responses, including the InternalServerError
status for HTTP 500 errors:
var app = WebApplication.Create();
app.MapGet("/", () => TypedResults.InternalServerError("An error occurred."));
app.Run();
Another feature in this release is built-in OpenAPI document generation, made possible through the Microsoft.AspNetCore.OpenApi
package. Developers can now generate OpenAPI documents for controller-based and minimal APIs with basic configuration. This provides a simpler alternative to SwaggerGen, though it does not include a UI component like SwaggerUI, which was removed from .NET 9 templates. Developers can still manually add SwaggerUI if required.
On Reddit, user GaussZ clarified the implications of this change:
The OpenAPI support is not replacing SwaggerUI; it explicitly comes without any UI part. It only replaces the SwaggerGen part. You can still use the SwaggerUI though.
Updates have been made to authentication and authorization, now incorporating support for Pushed Authorization Requests (PAR) within OpenID Connect workflows. Developers can customize parameters in OAuth and OpenID Connect handlers, allowing for better control over authentication processes.
Further details on the new features can be found in the release note.