What do we do with errors—exceptions caught during the processing of a request, for example, when a resource is not found? You can use routing for this. Here, we will present a few strategies:
- Routing
- Adding a catch-all route
- Showing developer error pages
- Using the status code pages middleware
We will learn about these in the following sections.
Routing errors to controller routes
You can force a specific controller's action to be called when an error occurs by callingUseExceptionHandler:
app.UseExceptionHandler("/Home/Error");
What you put in this view (Error) is entirely up to you, mind you.
You can even do something more interesting, that is, register middleware to execute upon the occurrence of an error, as follows:
app.UseExceptionHandler(errorApp => { errorApp.Run(async context => { var errorFeature...