liveBook · Manning

UseStatusCodePagesWithReExecute

As explained in ASP.NET Core in Action, 3e

UseStatusCodePagesWithReExecute is an ASP.NET Core application-builder extension method that configures status-code middleware to reexecute a request through an error-handling path.

UseStatusCodePagesWithReExecute configures status-code middleware to reexecute the request through an error-handling path. This lets the application return a friendly, dynamically generated page while preserving the original status code. section 15.5

Configure a reexecute path

Add app.UseStatusCodePagesWithReExecute("/{0}"); to the application pipeline. A failed request with status code 404 is reexecuted using /404, which generates the HTML response while the browser still receives 404. section 15.5

app.UseStatusCodePagesWithReExecute("/{0}");

The listing shows the format-string configuration used to map a status code to an error-handling path. section 15.5

Choose a path the application can handle reliably. Dynamic error pages keep application-generated content consistent, but a static page is safer when the error-handling path might fail. section 15.5

How ASP.NET Core in Action, 3e covers it

How deep it goes
Explains format-string configuration, pipeline reexecution, preserved status codes, and static-page failure mitigation.
Examples
Uses a 404 request reexecuted through /404 and contrasts it with a 302 redirect to the same path.
What it assumes
Assumes an application pipeline and an error-handling path capable of generating the response.
What you can do after
Operate/configure ASP.NET Core status-code middleware with a format string for application-handled error paths.
How it connects
Connects ASP.NET Core middleware with HTTP status codes, error pages, Razor Pages, and redirects.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ASP.NET Core in Action, 3e. The section links point to the parts of the book it draws on.