-
Couldn't load subscription status.
- Fork 10.5k
Description
The DefaultFilesMiddleware, DirectoryBrowserMiddleware, and StaticFileMiddleware currently no-op (fall through to the next middleware in the pipeline) if they detect the request has an active endpoint (see code here).
This prevents the middleware from running even in cases where there's an endpoint with a null RequestDelegate. This prevents the ability to have an active endpoint for the purposes of communicating metadata to middleware while allowing middleware like the StaticFileMiddleware to keep performing its function, e.g. have a "dummy" endpoint to carry IAuthorizeData metadata so that the AuthorizationMiddleware performs authorization on a request before the StaticFileMiddleware runs (example here).
We should consider updating the check in these middleware to instead only no-op if the active endpoint's request delegate is null, i.e.:
// Return true because we only want to run if there is no endpoint request delegate.
private static bool ValidateNoEndpointRequestDelegate(HttpContext context) => context.GetEndpoint()?.RequestDelegate == null;If there are other middleware with similar behavior we should consider updating those in a similar fashion.