I am using asp.net core 2.1, the source for StatusCodePagesMiddleware.cs
if (!statusCodeFeature.Enabled)
{
// Check if the feature is still available because other middleware (such as a web API written in MVC) could
// have disabled the feature to prevent HTML status code responses from showing up to an API client.
return;
}
appears to present the assumption that the API middleware disables the handler, however it does not. Is there a cleaner way to enable the middleware only for MVC requests without a call to app.UseWhen and checking the path string, or is this the best approach?
app.UseWhen(
context => !context.Request.Path.Value.StartsWith("/api", StringComparison.OrdinalIgnoreCase),
builder => builder.UseStatusCodePagesWithReExecute("/.../{0}"));