liveBook · Manning

DeveloperExceptionPageMiddleware

As explained in Building Web APIs with ASP.NET Core

DeveloperExceptionPageMiddleware is ASP.NET Core middleware that captures pipeline exceptions and generates an HTML page containing detailed diagnostic information.

DeveloperExceptionPageMiddleware is ASP.NET Core middleware that captures synchronous and asynchronous exceptions from the HTTP pipeline and generates an HTML developer exception page. The page can include a stack trace, query-string parameters, cookies, and headers, making failures easier to investigate during development. section 2.4.3

Configure it as an environment-specific pipeline choice:

  • Register it with app.UseDeveloperExceptionPage() inside app.Environment.IsDevelopment(). section 2.4.3
  • Use app.UseExceptionHandler("/error") for staging and production instead of exposing detailed exception data. section 2.4.3
  • Treat the developer page as sensitive: diagnostic output can expose configuration settings or vulnerabilities to attackers. section 2.4.3
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/error");
}

The configuration shows the intended split: the developer exception page runs in development, while the /error exception handler runs elsewhere. section 2.4.3

Verify the developer page

Add a test endpoint that throws a new Exception("test"), then request it while the application runs in development. The response should display the developer exception page; moving the same configuration to a nondevelopment environment should use the /error handler instead. section 2.4.3

How Building Web APIs with ASP.NET Core covers it

How deep it goes
Explains synchronous and asynchronous exception capture, diagnostic contents, environment selection, and a verification endpoint.
Examples
Uses Program.cs configuration and test endpoints that throw Exception("test") to demonstrate generated error responses.
What it assumes
Assumes familiarity with Program.cs, middleware registration, environment checks, and HTTP routes.
What you can do after
Diagnose/debug with it by enabling detailed development errors and routing nondevelopment failures through /error.
How it connects
Connects middleware, HTTP pipelines, ASP.NET Core environments, exception handling, and Swagger/OpenAPI configuration.

Also explained in

Compare how 2 books explain DeveloperExceptionPageMiddleware →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building Web APIs with ASP.NET Core. The section links point to the parts of the book it draws on.