Do you present the user with a nice error screen?

Last updated by Brady Stroud [SSW] over 2 years ago.See history

Your users should never see the “yellow screen of death”. Errors should be caught, logged and a user-friendly screen displayed to the user.

error screen bad
Figure: Bad Example – ASP.NET Yellow Screen of Death

net core default
Figure: Bad Example - Default exception page

error screen good
Figure: Good Example - GitHub custom error page

However, as a developer you still want to be able to view the detail of the exception in your local development environment.

How-to set up development environment exception pages in ASP.NET Core

To set up exceptions in your local development environment you need to configure the Developer Exception Page middleware in the request processing pipeline. Unless you have modified the default template, it should work out of the box. Here are the important lines:

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
    }
    else
    {
        app.UseExceptionHandler("/Error");
        app.UseHsts();
    }
    ...
}

net core development
Figure: This is how you set it up in .NET 5

Find out more about exception handling in .NET Core 5 here.

We open source. Powered by GitHub