Skip to content

Commit dd78055

Browse files
authored
v9: Remove install endpoint as valid endpoint (#11710)
* Remove installer endpoint from valid candidates * Removed unrelevant change
1 parent 980cf00 commit dd78055

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

src/Umbraco.Web.BackOffice/Install/InstallController.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using Umbraco.Cms.Core.Services;
1414
using Umbraco.Cms.Core.WebAssets;
1515
using Umbraco.Cms.Infrastructure.Install;
16+
using Umbraco.Cms.Web.Common.Attributes;
1617
using Umbraco.Cms.Web.Common.Filters;
1718
using Umbraco.Extensions;
1819

@@ -101,6 +102,7 @@ public async Task<ActionResult> Index()
101102
/// </summary>
102103
/// <returns></returns>
103104
[HttpGet]
105+
[IgnoreFromNotFoundSelectorPolicy]
104106
public ActionResult Redirect()
105107
{
106108
var uri = HttpContext.Request.GetEncodedUrl();
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
3+
namespace Umbraco.Cms.Web.Common.Attributes
4+
{
5+
/// <summary>
6+
/// When applied to an api controller it will be routed to the /Umbraco/BackOffice prefix route so we can determine if it
7+
/// is a back office route or not.
8+
/// </summary>
9+
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
10+
public sealed class IgnoreFromNotFoundSelectorPolicyAttribute : Attribute
11+
{
12+
}
13+
}

src/Umbraco.Web.Website/Routing/NotFoundSelectorPolicy.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Microsoft.AspNetCore.Routing;
99
using Microsoft.AspNetCore.Routing.Matching;
1010
using Umbraco.Cms.Core.Routing;
11+
using Umbraco.Cms.Web.Common.Attributes;
1112
using Umbraco.Cms.Web.Common.Controllers;
1213
using Umbraco.Cms.Web.Common.Routing;
1314

@@ -35,7 +36,7 @@ private Endpoint GetNotFoundEndpoint()
3536
// return the endpoint for the RenderController.Index action.
3637
ControllerActionDescriptor descriptor = x.Metadata?.GetMetadata<ControllerActionDescriptor>();
3738
return descriptor?.ControllerTypeInfo == typeof(RenderController)
38-
&& descriptor?.ActionName == nameof(RenderController.Index);
39+
&& descriptor?.ActionName == nameof(RenderController.Index);
3940
});
4041
return e;
4142
}
@@ -45,7 +46,7 @@ private Endpoint GetNotFoundEndpoint()
4546
public bool AppliesToEndpoints(IReadOnlyList<Endpoint> endpoints)
4647
{
4748
// Don't apply this filter to any endpoint group that is a controller route
48-
// i.e. only dynamic routes.
49+
// i.e. only dynamic routes.
4950
foreach (Endpoint endpoint in endpoints)
5051
{
5152
ControllerAttribute controller = endpoint.Metadata?.GetMetadata<ControllerAttribute>();
@@ -80,11 +81,15 @@ private static bool AllInvalid(CandidateSet candidates)
8081
{
8182
for (int i = 0; i < candidates.Count; i++)
8283
{
83-
if (candidates.IsValidCandidate(i))
84+
// We have to check if candidates needs to be ignored here
85+
// So we dont return false when all endpoints are invalid
86+
if (candidates.IsValidCandidate(i) &&
87+
candidates[i].Endpoint.Metadata.GetMetadata<IgnoreFromNotFoundSelectorPolicyAttribute>() is null)
8488
{
8589
return false;
8690
}
8791
}
92+
8893
return true;
8994
}
9095
}

0 commit comments

Comments
 (0)