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

