In our previous post, we introduced the exciting new features in .NET 8 Preview, highlighting the various improvements and enhancements it brings to the .NET ecosystem. With the recent availability of .NET 8 Preview 4, we're thrilled to dive deeper into the significant updates it offers to ASP.NET Core. This release includes a host of advancements in Blazor, API authoring, Native AOT support, and authentication and authorization. In this blog post, we'll guide you through these new features, providing insights and examples to help you take advantage of everything .NET 8 Preview 4 has to offer in your ASP.NET Core projects. So, let's get started!
As one of the fastest-growing modern frameworks, Blazor has undoubtedly made an impact in the world of web development. With the .NET 8 Preview 4 release, we can expect generous enhancements that aim to improve user experiences and broaden development possibilities.
Server-side rendering (SSR) with Blazor components now allows streaming content updates through the response stream. This feature significantly improves the user experience. To implement streaming rendering with Blazor components, follow these steps:
Streaming is a feature that the whole web development community started to be interested in thanks to React, and its version 18. We wrote more about it here.
One of the new features in Blazor SSR is the ability to handle form posts in a more streamlined manner. This improvement simplifies the process of creating web forms and processing their submissions. Here's how you can take advantage of this functionality in Blazor:
The updated Blazor SSR form handling will enable developers to create more dynamic and interactive web forms, elevating the user experience.
In .NET 8 Preview 4, Blazor introduces support for client-side routing that allows navigation to specific HTML elements on a page using standard URL fragments. This means that if you assign an identifier to an HTML element using the `id` attribute, Blazor will automatically scroll to that element when the URL fragment matches the element identifier. This feature offers a seamless and direct way to navigate through various sections of a webpage.
With the introduction of Webcil in .NET 8 Preview 4, developers can now benefit from a web-friendly packaging of .NET assemblies that removes content specific to native Windows execution. This eliminates issues related to deploying environments that block .dll file downloads or use.
To enable the usage of Webcil for your Blazor WebAssembly apps, simply add the WasmEnableWebcil property to your project file:
If you encounter any issues while using .webcil files in your environment, please report them by creating an issue on GitHub.
API authoring capabilities have been expanded, allowing for a more comprehensive and efficient development process.
This release brings an extensive range of support for form binding in minimal APIs. Form-based parameters are now inferred without the need for the FromForm attribute. This advanced support includes IFormCollection, IFormFile, IFormFileCollection, and OpenAPI metadata. By leveraging these improvements, developers can create more robust and flexible APIs that cater to various scenarios and requirements.
The API project template now comes with an .http file, allowing developers to send requests to defined endpoints within the application directly from the new HTTP editor in Visual Studio. This streamlined approach will enable developers to quickly test and iterate their APIs, ensuring a more efficient development process.
With these API authoring updates, developers can expect a more seamless and powerful experience when working with ASP.NET Core in .NET 8 Preview 4.
.NET 8 Preview 4 also brings advancements to Native AOT, offering better performance, configurability, and support for various app features.
Request Delegate Generator (RDG) is introduced in .NET 8 Preview 4 to improve the handling of parameter binding failures, logging, and exception handling for compile-time generated minimal APIs. With RDG, developers can quickly identify and respond to bad HTTP request exceptions, ensuring a smoother user experience.
To help developers identify features that are incompatible with Native AOT, the main entry points to subsystems have been annotated. This allows developers to see warnings when calling methods that are not trim-safe, ensuring they understand issues that may arise when working with Native AOT.
With the updated WebApplication.CreateSlimBuilder() in .NET 8 Preview 4, configurable HTTPS support allows for a reduced app size that excludes default HTTPS or HTTP/3 support. This improvement is beneficial for apps running behind a TLS termination proxy, like those hosted on Azure. The lighter app size results in faster load times and better overall performance.
Worker Service templates in .NET 8 Preview 4 now include support for the --aot flag, enabling developers to create worker service projects with AOT publishing enabled. This update simplifies the configuration process and optimizes the published app's performance.
The WebApplication.CreateSlimBuilder() API now includes additional default services to improve the development experience while maintaining a total app size below 10 MB. These default services include JSON file configuration, user secrets configuration, console logging, and logging configuration.
The .NET 8 Preview 4 release has updated JsonSerializerOptions.TypeInfoResolverChain API, providing developers with more control over JSON configuration in their API templates.
The .NET 8 Preview 4 release introduces support for JSON serialization of IAsyncEnumerable<T> implementations implemented by the C# compiler. This enables the use of IAsyncEnumerable<T> in ASP.NET Core projects configured to publish native AOT, which is particularly useful when working with asynchronously returned enumerations.
With these advancements in Native AOT, developers can expect better performance, configurability, and support for their applications in .NET 8 Preview 4.
This release also brings enhancements to authentication and authorization within ASP.NET Core, improving the overall security and customization of your applications.
The new MapIdentityApi<TUser>() extension method introduces two new API endpoints: /register and /login. These endpoints aim to simplify the process of integrating ASP.NET Core Identity into JavaScript-based single-page apps (SPA) or Blazor apps. The Identity API endpoints provide a more suitable solution for SPA and mobile applications by replacing the default ASP.NET Core Identity UI with JSON API endpoints.
Custom authorization policies have also been improved in .NET 8 Preview 4. By leveraging the IAuthorizationRequirementData interface, developers can implement custom authorization policies with fewer lines of code and more flexibility. This improvement allows for better customization and enhanced security in your applications.
In conclusion, the .NET 8 Preview 4 release brings a plethora of enhancements to the ASP.NET Core ecosystem, equipping developers with sophisticated tools and features to build and deploy high-performance web applications more efficiently. With continued updates and improvements, ASP.NET Core in .NET 8 is poised to become an essential framework for modern web development.
One of the most valuable additions to .NET 8 Preview 4 is the implementation of ASP.NET Core metrics. Metrics are essential for monitoring the health of your application and generating alerts. With the addition of System.Diagnostics.Metrics throughout ASP.NET Core hosting, Kestrel, and SignalR, developers now gain access to a powerful set of tools that help ensure their applications run smoothly and efficiently.
As you can’t manage if you can’t track/measure, these improvements are more important than one would think.
The Metrics API offers several improvements over existing event counters:
Metrics introduces new measurement types, such as counters, gauges, and histograms, giving developers a more comprehensive set of data points to monitor and track their applications' performance.
Metrics support multi-dimensional values, allowing for more nuanced and detailed reporting. This powerful feature enables developers to gain deeper insights into their applications' behavior and troubleshoot issues more effectively.
By aligning with OpenTelemetry standards, Metrics ensures seamless integration into the broader cloud-native ecosystem. This compatibility makes it easier for developers to adopt and leverage Metrics in their ASP.NET Core projects.
With the implementation of ASP.NET Core Metrics in .NET 8 Preview 4, developers can expect a more streamlined and efficient approach to monitoring application health and generating alerts. The enhanced metrics capabilities will enable developers to create and maintain high-quality, performant applications with greater ease.
The .NET 8 Preview 4 release significantly elevates the capabilities of ASP.NET Core, providing developers with a powerful framework and cutting-edge features to create high-performance web applications. With updates to Blazor, enhancements to API authoring, advancements in Native AOT support, improved authentication and authorization, and the introduction of ASP.NET Core Metrics, developers can expect a more streamlined and efficient development experience.
As the ASP.NET Core ecosystem continues to innovate and evolve, it's crucial for developers to stay up-to-date with the latest advancements and best practices. The rich offering of features in .NET 8 Preview 4 showcases the commitment to delivering an essential framework for modern web development. Embrace these updates, explore the new possibilities, and stay tuned for future releases as ASP.NET Core paves the way for the next generation of web applications.