In Statup.cs -> Configure:
app.UseStatusCodePagesWithReExecute("/StatusCodeError/{0}");
The code for that middleware is here and