Better exception details with ASP.NET Core
By default, ASP.NET Core suppresses Exceptions on Startup on external environments. So you only get Exceptions in Startup
on localhost.
Sometimes, especially on remote hosts like Azure, AWS or hosted virtual machines you deploy your app and you only get:
This does not help, if you do not log this error to an external data blob like Application Insights.
Enable error details
Often this happens if you forget to copy a dependency or have a typo in your settings files. But this is hard to debug! Also, the entire application process cashes, which is the reason you cannot normally attach a debuger (it never worked for me!).
To get a better error detail you have to activate detailed errors
.
Open your program.cs
and add .UseSetting("detailedErrors", "true")
and .CaptureStartupErrors(true)
.
It now should look like
namespace BenjaminAbt.ErrorHandlingSample
{
public class Program
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseApplicationInsights()
.UseStartup<Startup>()
.UseSetting("detailedErrors", "true")
.CaptureStartupErrors(true)
.Build();
host.Run();
}
}
}
Now you get on remote a detailed error page, too.