DeveloperExceptionPageMiddleware helps debug unhandled exceptions during ASP.NET Core development. When an exception propagates up the middleware pipeline to it, the middleware captures the exception and returns a diagnostic HTML page with a 500 status code. section 4.3.1
The page shows the exception stack trace, the location and source line where the exception occurred, and request details. Query, Cookies, Headers, and Routing controls reveal further information about the request. section 4.3.1
Figure 4.15 The developer exception page shows details about the exception when it occurs during the process of a request. The location in the code that caused the exception, the source code line itself, and the stack trace are all shown by default. You can also click the Query, Cookies, Headers, and Routing buttons to reveal further details about the request that caused the exception.
Inspect the diagnostic page and its request-detail controls. section 4.3.1
WebApplication automatically adds this middleware at the start of the pipeline in the Development environment. You can therefore omit an explicit call to app.UseDeveloperExceptionPage() in that setup. When adding it explicitly, place it early enough in the pipeline to receive exceptions from later middleware. section 4.2.3 section 4.3.1
Registering the middleware
Call app.UseDeveloperExceptionPage(); when explicitly adding the middleware to a development pipeline. With WebApplication in Development, the automatic addition normally makes this call unnecessary. section 4.3.1
Never use the developer exception page in production: its diagnostic details can expose application code and other sensitive information. Use ExceptionHandlerMiddleware instead to return a controlled, user-friendly error response. Applications commonly add it conditionally when the environment is not Development. section 4.3.1 section 4.3.2
Listing 4.5 Adding exception-handler middleware when in production
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
WebApplication app = builder.Build(); #1
if (!app.Environment.IsDevelopment()) #2
{
app.UseExceptionHandler("/error"); #3
}
// additional middleware configuration
app.MapGet("/error", () => "Sorry, an error occurred"); #4
See a conditional production handler with an /error endpoint. section 4.3.2

