diff --git a/Lombiq.HelpfulLibraries.OrchardCore/Mvc/TypedRoute.cs b/Lombiq.HelpfulLibraries.OrchardCore/Mvc/TypedRoute.cs index 8e971671..85fd4b78 100644 --- a/Lombiq.HelpfulLibraries.OrchardCore/Mvc/TypedRoute.cs +++ b/Lombiq.HelpfulLibraries.OrchardCore/Mvc/TypedRoute.cs @@ -91,7 +91,9 @@ public string ToString(HttpContext httpContext) /// public override string ToString() { - var prefix = _isAdminLazy.Value ? "/Admin/" : "/"; + var isAdminWithoutRoute = _isAdminLazy.Value && _action.GetCustomAttribute(typeof(RouteAttribute)) == null; + + var prefix = isAdminWithoutRoute ? "/Admin/" : "/"; var route = _routeLazy.Value; var arguments = _arguments.Any() ? "?" + string.Join('&', _arguments.Select((key, value) => $"{key}={WebUtility.UrlEncode(value)}")) diff --git a/Lombiq.HelpfulLibraries.Tests/Controllers/RouteTestController.cs b/Lombiq.HelpfulLibraries.Tests/Controllers/RouteTestController.cs index d35516b1..bffbbeb3 100644 --- a/Lombiq.HelpfulLibraries.Tests/Controllers/RouteTestController.cs +++ b/Lombiq.HelpfulLibraries.Tests/Controllers/RouteTestController.cs @@ -18,6 +18,10 @@ public class RouteTestController : Controller [Route("I/Am/Routed")] public IActionResult Route() => Content(string.Empty); + [Admin] + [Route("I/Am/Routed/Admin")] + public IActionResult AdminRoute() => Content(string.Empty); + [Route("content/{id}")] public IActionResult RouteSubstitution(int id) => Content(string.Empty); diff --git a/Lombiq.HelpfulLibraries.Tests/UnitTests/Models/TypedRouteTests.cs b/Lombiq.HelpfulLibraries.Tests/UnitTests/Models/TypedRouteTests.cs index c6127736..00affe55 100644 --- a/Lombiq.HelpfulLibraries.Tests/UnitTests/Models/TypedRouteTests.cs +++ b/Lombiq.HelpfulLibraries.Tests/UnitTests/Models/TypedRouteTests.cs @@ -91,6 +91,13 @@ static Expression> AsExpression( noTenant, }, new object[] + { + "/I/Am/Routed/Admin", + AsExpression(controller => controller.AdminRoute()), + noMoreArguments, + noTenant, + }, + new object[] { "/I/Am/Routed?wat=is+this", AsExpression(controller => controller.Route()),