Blog #23

Features of ASP.NET Core

 18 May 2019

Features of ASP.NET Core

It's been a while since Microsoft introduced .NET Core and with it ASP.NET Core. The new ecosystem has evolved over time, from a basic set of features at the initial launch, missing a lot of the functionality from the full .NET Framework, to a far wider range of functionality today, with some new and re-imagined features. In this article I am going to give an overview of some of the new features of ASP.NET Core.


Razor Pages

ASP.NET Core 2 brought with it Razor Pages. These are stand alone pages in MVC that do not require a controller. By adding the @Page directive at the top of any cshtml file, MVC knows this page is a Razor Page and will be able to serve it without a method on a controller.


SPA Templates

A huge trend on the web at the moment is to use a single page application template, such as Angular or React. ASP.NET core recognises this and provides templates out of the box for Angular, React, or React with Redux, the three most popular options on the web at the moment. This saves a lot of time and configuration if you do wish to go with the single page application format.

DbContext Pooling

If you use Entity Framework, this change is huge. Using the built in dependency injection with ASP.NET Core, you can now setup your DbContext to use pooling:

services.AddDbContextPool<MyContext>(

    options => options.UseSqlServer(connectionString)

);

The above code will setup a pool of DbContexts and will reset them and reuse them as required. This removes the overhead of creating DbContexts on demand, whilst letting you use a context per request.

SignalR

Coming soon in ASP.NET Core 2.1 (currently in preview) is SignalR. If you've used this technology in regular ASP.NET then you'll have experienced how simple this makes real time communication. The entire SignalR library has been rethought from the ground up for ASP.NET Core and hence only being released in 2.1. The idea is to support many more communication protocols in ASP.NET Core, beyond HTTP and web. There is far too much to explain in this post, but this video from Build 2017 does a good job.

Use HTTPS Redirection

A very simple, but very useful feature is the introduction of the app.UseHttpsRedirection() method that can be used during configuration to redirect all traffic to HTTPS.

Also coming in ASP.NET Core 2.1 is the app.UseHsts() method which is an opt-in security enhancement. This passes the Http Strict Transport Security (HSTS) header. A supported browser will then prevent any communications over HTTP.

Find Out More

There is plenty more in ASP.NET Core including powerful fluid configuration options, security, logging and hosting. I recommend viewing the Microsoft documentation on ASP.NET Core to explore some of the new features, release notes and more. Following that, open up Visual Studio and pick one of the new templates to explore ASP.NET Core in practice.

About the Author

Paul Burgess is a Lead Developer, and creator of various open source libraries: http://github.com/codepb

Comments

Currently there are no comments. Be the first to post one!

Post Comment

*
*
*