

For an MVC app, the project template includes an Error action method and an Error view for the Home controller.

cshtml) and PageModel class ( ErrorModel) in the Pages folder. The Razor Pages app template provides an Error page (. In the following example, UseExceptionHandler adds the exception handling middleware in non-Development environments: var app = builder.Build() Request data such as headers, method, and items are all reused as-is. For the UseExceptionHandler(IApplicationBuilder, String) overload that is used in templates, only the request path is modified, and the route data is cleared.When dealing with the request body, this either means buffering or caching the results like the Form reader. This normally means either cleaning up their state after calling _next or caching their processing on the HttpContext to avoid redoing it. Middlewares need to handle reentrancy with the same request.Since this middleware can re-execute the request pipeline: If the alternate pipeline throws an exception of its own, Exception Handling Middleware rethrows the original exception. The template-generated code re-executes the request using the /Error path. The request isn't re-executed if the response has started. Re-executes the request in an alternate pipeline using the path indicated.To configure a custom error handling page for the Production environment, call UseExceptionHandler. Use Logging for complete error information. The Developer Exception Page isn't guaranteed to provide any information. The Developer Exception Page can include the following information about the exception and the request: For more information on configuring environments, see Use multiple environments in ASP.NET Core. The developer exception page runs early in the middleware pipeline, so that it can catch unhandled exceptions thrown in middleware that follows.ĭetailed exception information shouldn't be displayed publicly when the app runs in the Production environment. Apps created using the WebHost.CreateDefaultBuilder must enable the developer exception page by calling app.UseDeveloperExceptionPage in Configure. App created with the current templates, that is, using WebApplication.CreateBuilder.Running in the Development environment.ASP.NET Core apps enable the developer exception page by default when both: The Developer Exception Page displays detailed information about unhandled request exceptions. See Handle errors in ASP.NET Core web APIs for web APIs. This article covers common approaches to handling errors in ASP.NET Core web apps.
