Exception Handling in Asp.NET Core 6.0
ASP.NET Core Exception Handling in Development and Production Environments.
We can catch all exceptions by Adding a Dedicated Action Method
We can also add a common Action method which will be called everything some error occurs in our application.
We also want this common action method should only be called in Production environment.
1. Create an Action method in your Home Controller
2. Add a Razor View called Error inside the Views ➤ Home
3. update the program.cs for development and production environment
Now what we want is that:
1. When the application is running in production environment the users will see a simple text message telling them there is
some problem which will be rectified in a moment so come back after sometime.
2. When the application is running in Development environment then users will see full error details.
The UseExceptionHandler adds Middleware to catch exceptions occurring in our ASP.NET Core applications. The app.UseExceptionHandler(“/Home/Error”) sets the error path which is “/Home/Error”, here custom user friendly error messages can be displayed to the user