New Features In ASP.NET Core 2.0

Introduction

ASP.NET Core is a significant redesign of ASP.NET. It is an open source and cross-platform framework for developing cloud based applications like web applications, IoT applications, and the mobile back-end applications.

In this article, I will highlight the new features and the modified existing features of ASP.NET Core.

Razor Pages

It is a new feature of ASP.NET Core MVC, which makes coding page-focused scenarios easier and more productive. To work with Razor pages, we need to use .NET Core 2.0 or higher framework. This feature has introduced many more page directives, such as @function.

Meta Packages

The new framework introduced Meta package that includes all of the packages supported by ASP.NET Core and EF (Entity Framework) core with their internal and 3rd-party dependencies. Using these meta packages, we need not select individual ASP.NET Core features by the package but the assembly Microsoft.AspNetCore. All packages contain all the features.

.NET Standard 2.0

It also targets .NET Standard 2.0. It can be referenced by other .NET Standard 2.0 libraries and they can run on its compliant implementations of .NET that include .NET Core 2.0 and .NET Framework 4.6.1.

Kestrel Web Server improvements

It has new features that are suitable for an Internet-facing Server. In KestrelServerOptions class, we can add a number of server constraint configuration options. This class has new Limits property using which we can limit -
  • Maximum request body size
  • Maximum client connections
  • Minimum request body data rate
HTTP.sys

It is a web server for ASP.NET Core, and very similar to Kestrel Web Server. It only runs on Windows. The .NET Core 1.x has packages Microsoft.AspNetCore.Server.WebListener and Microsoft.Net.Http.Server which are merged into a new package "Microsoft.AspNetCore.Server.HttpSys".

Update in Configuration

In ASP.NET Core 2.0, IConfiguration interface instance is added to the service container. This makes it easier for applications to retrieve the configuration values from the service container.

Update in Logging

In the new version of the framework, Logging is added into DI (dependency injection) system by default. We need to add providers and configure filtering in main function (program.cs file) instead of defining in the Startup class.

Update in Authentication Model

The new authentication model makes it easier to configure authentication for an application using dependency injection (DI).

Update in Identity

With ASP.NET Core 2.0, it is easy to build secure web APIs using Identity. MSAL (Microsoft Authentication Library) provides access token for accessing the Web API.

New SPA (Single Page Application) project Templates

SPA project templates for Knockout.js, React.js, React.js with Redux, Aurelia, and Angular are available. The Angular template has been updated with Angular version 4.0. The React and Angular templates are available by default.

Added support for C# 7.1 in Razor

The Razor View Engine is now compatible with new Roslyn compiler that adds support for a new feature of C# 7.1, such as Inferred Tuple Names, Default Expressions, and Pattern-Matching with Generics. To use C# 7.1 in our project, we need to specify "LangVersion" property to latest in our project file.

Runtime Store

The .NET Core 2.0 introduces meta package (Microsoft.AspNetCore.All). The application can take the advantage of new .NET Core Runtime store that is used in this meta-package. It contains all the assets required to run the application. We do not need to reference any other assets from NuGet packages when we use this meta-package. All the assets are precompiled so it helps us improve the startup performance of an application.

Automatic pre-compilation of Razor View

In .NET Core 2.0, the Razor View is automatically pre-compiled during the publishing by default. It helps us reduce the published output size and application startup time.

Automatic use of anti-forgery tokens

ASP.NET Core supports the HTML encoding of our page content but this new version of framework takes care of cross-site request forgery (XSRF) attacks. ASP.NET Core emits anti-forgery tokens and validates it on form POST without any extra configuration.

Application Insights diagnostics

Hosting environment is added in extra dependency packages and it executes code during the startup without taking any external dependency or calling to any methods. In the new framework, this feature is used to enable automatic application insights diagnostics when the application is running / debugging in Visual Studio and running in Azure App Services.

Summary

ASP.NET Core is released with many new features while several features are enhanced. Please see ASP.NET Core 2.0 Release Notes for a complete list of changes

Up Next
    Ebook Download
    View all
    Learn
    View all