diff --git a/src/Umbraco.Web.Website/Routing/NotFoundSelectorPolicy.cs b/src/Umbraco.Web.Website/Routing/NotFoundSelectorPolicy.cs index e9370c94ce..dbc06175fd 100644 --- a/src/Umbraco.Web.Website/Routing/NotFoundSelectorPolicy.cs +++ b/src/Umbraco.Web.Website/Routing/NotFoundSelectorPolicy.cs @@ -24,7 +24,7 @@ namespace Umbraco.Cms.Web.Website.Routing public NotFoundSelectorPolicy(EndpointDataSource endpointDataSource) { _notFound = new Lazy(GetNotFoundEndpoint); - _endpointDataSource = endpointDataSource; + _endpointDataSource = endpointDataSource; } // return the endpoint for the RenderController.Index action. @@ -46,7 +46,7 @@ namespace Umbraco.Cms.Web.Website.Routing { // Don't apply this filter to any endpoint group that is a controller route // i.e. only dynamic routes. - foreach(Endpoint endpoint in endpoints) + foreach (Endpoint endpoint in endpoints) { ControllerAttribute controller = endpoint.Metadata?.GetMetadata(); if (controller != null) @@ -61,7 +61,7 @@ namespace Umbraco.Cms.Web.Website.Routing public Task ApplyAsync(HttpContext httpContext, CandidateSet candidates) { - if (candidates.Count == 1 && candidates[0].Values == null) + if (AllInvalid(candidates)) { UmbracoRouteValues umbracoRouteValues = httpContext.Features.Get(); if (umbracoRouteValues?.PublishedRequest != null @@ -72,8 +72,20 @@ namespace Umbraco.Cms.Web.Website.Routing httpContext.SetEndpoint(_notFound.Value); } } - - return Task.CompletedTask; + + return Task.CompletedTask; + } + + private static bool AllInvalid(CandidateSet candidates) + { + for (int i = 0; i < candidates.Count; i++) + { + if (candidates.IsValidCandidate(i)) + { + return false; + } + } + return true; } } }