You are tasked to catch all unhandled exceptions globally in your ASP.NET Core MVC application. Which approach would be most suitable to achieve this?

  • Use the try...catch block in every action method.
  • Configure global exception handling in the Startup.cs file using app.UseExceptionHandler("/Home/Error").
  • Implement a custom exception filter for each controller.
  • Set MvcOptions.Filters.Add(new GlobalExceptionFilter()) in the Startup.cs file.
To catch all unhandled exceptions globally in an ASP.NET Core MVC application, you should configure global exception handling in the Startup.cs file using app.UseExceptionHandler("/Home/Error"). This route will handle unhandled exceptions and direct them to a specified error page.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *