Skip to content

Commit

Permalink
Include the PluginController Area when searching for matching surface… (
Browse files Browse the repository at this point in the history
  • Loading branch information
vwa-software authored and nikolajlauridsen committed Apr 20, 2022
1 parent ce6a3d6 commit f45d4a8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
22 changes: 19 additions & 3 deletions src/Umbraco.Web.Website/Routing/ControllerActionSearcher.cs
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Http;
Expand Down Expand Up @@ -31,13 +32,20 @@ public class ControllerActionSearcher : IControllerActionSearcher
_actionSelector = actionSelector;
}


/// <summary>
/// Determines if a custom controller can hijack the current route
/// </summary>
/// <typeparam name="T">The controller type to find</typeparam>
public ControllerActionDescriptor Find<T>(HttpContext httpContext, string controller, string action) => Find<T>(httpContext, controller, action, null);

/// <summary>
/// Determines if a custom controller can hijack the current route
/// </summary>
/// <typeparam name="T">The controller type to find</typeparam>
public ControllerActionDescriptor Find<T>(HttpContext httpContext, string controller, string action)
public ControllerActionDescriptor Find<T>(HttpContext httpContext, string controller, string action, string area)
{
IReadOnlyList<ControllerActionDescriptor> candidates = FindControllerCandidates<T>(httpContext, controller, action, DefaultActionName);
IReadOnlyList<ControllerActionDescriptor> candidates = FindControllerCandidates<T>(httpContext, controller, action, DefaultActionName, area);

if (candidates.Count > 0)
{
Expand All @@ -47,21 +55,29 @@ public ControllerActionDescriptor Find<T>(HttpContext httpContext, string contro
return null;
}


/// <summary>
/// Return a list of controller candidates that match the custom controller and action names
/// </summary>
private IReadOnlyList<ControllerActionDescriptor> FindControllerCandidates<T>(
HttpContext httpContext,
string customControllerName,
string customActionName,
string defaultActionName)
string defaultActionName,
string area = null)
{
// Use aspnetcore's IActionSelector to do the finding since it uses an optimized cache lookup
var routeValues = new RouteValueDictionary
{
[ControllerToken] = customControllerName,
[ActionToken] = customActionName, // first try to find the custom action
};

if (area != null)
{
routeValues[AreaToken] = area;
}

var routeData = new RouteData(routeValues);
var routeContext = new RouteContext(httpContext)
{
Expand Down
6 changes: 6 additions & 0 deletions src/Umbraco.Web.Website/Routing/IControllerActionSearcher.cs
@@ -1,10 +1,16 @@
using System;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Controllers;

namespace Umbraco.Cms.Web.Website.Routing
{
public interface IControllerActionSearcher
{

ControllerActionDescriptor Find<T>(HttpContext httpContext, string controller, string action);

ControllerActionDescriptor Find<T>(HttpContext httpContext, string controller, string action, string area)
=> Find<T>(httpContext, controller, action);

}
}
Expand Up @@ -240,7 +240,7 @@ private RouteValueDictionary HandlePostedValues(PostedDataProxyInfo postedInfo,
[ActionToken] = postedInfo.ActionName
};

ControllerActionDescriptor surfaceControllerDescriptor = _controllerActionSearcher.Find<SurfaceController>(httpContext, postedInfo.ControllerName, postedInfo.ActionName);
ControllerActionDescriptor surfaceControllerDescriptor = _controllerActionSearcher.Find<SurfaceController>(httpContext, postedInfo.ControllerName, postedInfo.ActionName, postedInfo.Area);

if (surfaceControllerDescriptor == null)
{
Expand Down

0 comments on commit f45d4a8

Please sign in to comment.