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.
Loading...
Related Quiz
- In the context of Azure, _________ App Service is a fully managed platform for building, deploying, and scaling web apps.
- Imagine you're working on an e-commerce application using ASP.NET Core MVC. A user wants to view details of a product. Which component of the MVC pattern would be responsible for fetching the product details from the database?
- In a scenario where you want to cache an action result for a specified duration, which attribute or method can be combined with an action result to achieve this behavior?
- Your college project involves creating a simple blog. Which ASP.NET Core template provides functionalities like user comments and posts out of the box?
- What is the primary role of Entity Framework Core in ASP.NET Core applications?