How it works...

Press Ctrl + F5 again to restart IIS Express and launch our application. You will see that our custom error page has been displayed inside the browser:

In reality, we will probably use a controller to do this kind of thing. What I wanted to illustrate here was the use of adding a custom default page and to display that page when an exception happens in the production environment. As you can see, middleware in ASP.NET Core is really useful. There is a lot of documentation regarding his topic, and I encourage you to do some further reading on the topic. Start with the Microsoft documentation at https://docs.microsoft.com/en-us/aspnet/core/fundamentals/middleware ...

Get C# 7 and .NET Core Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.