MiddlewarePipelineDebuggingWebApplicationExtensions Class

Extension methods to map middleware pipeline debugging endpoints.

public static class MiddlewarePipelineDebuggingWebApplicationExtensions

Methods

NameDescription
GetMiddlewarePipelineDebugSnapshot(WebApplication)Gets a middleware pipeline snapshot from code without using the debug route.
MapMiddlewarePipelineDebugEndpoint(WebApplication, string, bool)Maps a JSON endpoint that returns the middleware tree and endpoint list. By default, the endpoint responds only in Development and returns 404 elsewhere.

GetMiddlewarePipelineDebugSnapshot(WebApplication)

MiddlewarePipelineDebuggingWebApplicationExtensions.cs

Gets a middleware pipeline snapshot from code without using the debug route.

public static MiddlewarePipelineDebugSnapshot GetMiddlewarePipelineDebugSnapshot(this WebApplication app)

Parameters

app WebApplication
The web application.

Returns

MiddlewarePipelineDebugSnapshot The middleware pipeline snapshot.

Remarks

The pipeline is captured while the host builds it, so call this after the host has started. Before then, MiddlewarePipelineDebugSnapshot.IsPipelineCaptured is false and the pipeline is empty — notably inside an IHostedService registered before the web host.

MapMiddlewarePipelineDebugEndpoint(WebApplication, string, bool)

MiddlewarePipelineDebuggingWebApplicationExtensions.cs

Maps a JSON endpoint that returns the middleware tree and endpoint list. By default, the endpoint responds only in Development and returns 404 elsewhere.

[RequiresDynamicCode("This method maps a delegate endpoint that serializes the snapshot with reflection-based JSON serialization.")]
[RequiresUnreferencedCode("This method maps a delegate endpoint, which may use reflection and is not trim-safe.")]
public static RouteHandlerBuilder MapMiddlewarePipelineDebugEndpoint(this WebApplication app, string pattern = "/_debug/pipeline", bool developmentOnly = true)

Parameters

app WebApplication
The web application.
pattern string
The route pattern used for the debug endpoint.
developmentOnly bool
Indicates whether the endpoint should respond only in Development.

Returns

RouteHandlerBuilder The mapped route builder.

Remarks

The endpoint is not authenticated. It discloses every registered route, the middleware order, and implementation type names. When mapping it outside Development, gate it — the returned builder allows .RequireAuthorization().

The route is always registered so the return value can be chained; when developmentOnly is true and the environment is not Development, the handler responds 404 instead of returning the snapshot.