ASP.NET Core is a cross-platform, open-source framework for building cloud-based, internet-connected applications. With ASP.NET Core you can build web apps and services, deploy to the cloud or on-premises. It runs on .NET Core or .NET Framework. In this blog, we are going to see what are all the new features that are available in ASP.NET Core 2.1.0 Release notes.
What’s new in ASP.NET Core 2.1
In ASP.NET Core 2.1, the following features and improvements have been added to SignalR:
- A compact binary protocol has been introduced and you can also create custom protocols.
- The existing model has been simplified and a new streaming response model has been introduced.
Razor class libraries
In ASP.NET Core 2.1, there are various features added to Razor class libraries:
- There exists Razor SDK which enables the user to build the razor files into a class library project. This project will be packaged into a NuGet package.
- It also makes easier to build and include Razor-based UI in a library in which you can share it across multiple projects.
- When you integrate Razor with the build, the app startup time is faster and also there will be faster updates to razor views and pages at runtime.
Identity UI library & scaffolding
In ASP.NET Core 2.1, ASP.NET Core identity is being provided as a Razor Class Library. By using this library, you can:
- Include this identity in your apps to apply the new identity scaffolder to selectively add the source code contained in the Identity Razor Class Library.
- Sometimes you want to generate the source code and modify it later because you want to change the behavior of the source code.
- Apps that do not include authentication can apply for the Identity scaffolder to add the Razor Class Library Identity Package.
In ASP.NET Core 2.1, you can enable HTTPS for web apps. Because every browser is insisting to enforce the web features must be used from a secure context like HTTPS rather than HTTP. Anyway, using HTTPS in production is critical, but using HTTPS in development prevents issues in deployment. It makes the developer easier to use HTTPS in development and to configure HTTPS in production.
- HTTPS is now enabled by default. Now Kestrel listens on http://localhost:5001 when a local development certificate is present.
- The certificate is created as a part of .NET Core SDK first run experience and you can also create it manually using dev-certs To trust the certificate, you have to run dotnet dev-certs https –trust command.
- Web apps need to redirect all the HTTP traffic to HTTPS. In 2.1 the redirection has been enforced by using HTTP Strict Transport Security Protocol(HSTS) as a middleware which instructs the browser to always access the site via HTTPS.
- In production, you have to configure HTTPS explicitly but in 2.1 default configuration schema for configuring HTTPS for Kestrel has been added. Apps can be configured to use multiple endpoints including the URLs.
General Data Protection Regulation(GDPR)
GDPR support has been included in ASP.NET Core 2.1. It provides APIs and templates to help meet some of the EU General Data Protection Regulation(GDPR) requirements. They are:
- The templates include extension points and stubbed markup in which you can replace with your privacy and cookie use policy.
- A cookie consent feature allows you to ask for consent from your users to store personal information.
- Cookies can be marked as essential and these are sent to the browser even when the user has not consented and tracking is disabled however TempData and Session cookies are not functional when the tracking is disabled.
- The identity manage page provides a link to download and delete user data.
A new test package Microsoft.AspNetCore.Mvc.Testing has been introduced in 2.1. This package will handle the following tasks:
- It copies the dependency file(*.deps) from the tested app into the test projects bin folder and also sets the content root to tested app’s project root such that static files are found during test execution.
- It provides the WebApplicationactory class to streamline bootstrapping to the tested app with TestServer.
There are many new programming conventions that have been added to ASP.NET Core 2.1. It makes it easier to build and clean descriptive web APIs.
- ActionResult<T> is a new type which is added to the new programming convention which allows an app to return either response type or any other action result.
- [ApiController] attribute has been added such that to opt the users into Web API-specific conventions and behaviors.
A new service IHttpClientFactory has been introduced in ASP.NET Core 2.1, which makes it easier to consume instances of HttpClient in apps. HttpClient already has the concept of delegating handlers but the factory:
- It makes registering of instances of HttpClient per named client faster.
- It also implements a Polly handler which allows us to Polly policies to be used for Retry, CircuitBreakers etc.
Kernel Transport Configuration
In ASP.NET Core 2.1, Kestrel’s default transport is based on managed sockets. In previous versions, it was based on Libuv. Usually, for transport configuration it calls WebHostBuilderLibuvExtensions.UseLibuv package.
- The call of WebHostBuilderLibuvExtensions.UseLibuv depends on Microsoft.AspNetCore.Server.Kestrel package and Microsoft.AspNetCore.App package.
- For ASP.NET Core 2.1 or later projects, you have to use the Microsoft.AspNetCore.App.metapackage.asdasdasd
Generic Host Builder
In ASP.NET Core 2.1, Generic host builder has been introduced. It is mainly used for apps that don’t process HTTP requests.
- The main goal of Generic Host is to decouple the HTTP pipeline from the Web Host API.
- But it is not suitable for web hosting scenarios.
- The Web Host will be replaced by Generic Host which acts as a primary host API in both HTTP and non-HTTP scenarios.
Updated SPA Templates
The templates for Angular, React, and React with Redux has been updated to use the standard project structures and build systems for each framework.
- The updated Angular, React and React with Redux project template provides a convenient starting point for ASP.NET Core apps using Angular, React or React with Redux and the Angular CLI or create-react app(CRA) conventions to implement a rich, client-side user interface.
- Create a new angular project by using the command dotnet new angular.
- Create a react project by using the command dotnet new react.
- Create a react-redux project by using the command dotnet new reactredux.