From b457734f18054b96260de3d893c478623f5aa128 Mon Sep 17 00:00:00 2001 From: Ronald Barendse Date: Fri, 9 Sep 2022 09:45:38 +0200 Subject: [PATCH] Fix GetBackOfficeUrl extension method --- .../Extensions/LinkGeneratorExtensions.cs | 41 ++++++++----------- 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/src/Umbraco.Web.Common/Extensions/LinkGeneratorExtensions.cs b/src/Umbraco.Web.Common/Extensions/LinkGeneratorExtensions.cs index ce6e8c7816..70f8d1c2fe 100644 --- a/src/Umbraco.Web.Common/Extensions/LinkGeneratorExtensions.cs +++ b/src/Umbraco.Web.Common/Extensions/LinkGeneratorExtensions.cs @@ -13,32 +13,25 @@ namespace Umbraco.Extensions; public static class LinkGeneratorExtensions { /// - /// Return the back office url if the back office is installed + /// Gets the backoffice URL (if the back office is installed). /// - public static string? GetBackOfficeUrl(this LinkGenerator linkGenerator, IHostingEnvironment hostingEnvironment) - { - Type? backOfficeControllerType; - try - { - backOfficeControllerType = Assembly.Load("Umbraco.Web.BackOffice") - .GetType("Umbraco.Web.BackOffice.Controllers.BackOfficeController"); - if (backOfficeControllerType == null) - { - return "/"; // this would indicate that the installer is installed without the back office - } - } - catch - { - return - hostingEnvironment - .ApplicationVirtualPath; // this would indicate that the installer is installed without the back office - } + /// The link generator. + /// + /// The backoffice URL. + /// + public static string? GetBackOfficeUrl(this LinkGenerator linkGenerator) + => linkGenerator.GetPathByAction("Default", "BackOffice", new { area = Constants.Web.Mvc.BackOfficeArea }); - return linkGenerator.GetPathByAction( - "Default", - ControllerExtensions.GetControllerName(backOfficeControllerType), - new { area = Constants.Web.Mvc.BackOfficeApiArea }); - } + /// + /// Gets the backoffice URL (if the back office is installed) or application virtual path (in most cases just "/"). + /// + /// The link generator. + /// The hosting environment. + /// + /// The backoffice URL. + /// + public static string GetBackOfficeUrl(this LinkGenerator linkGenerator, IHostingEnvironment hostingEnvironment) + => GetBackOfficeUrl(linkGenerator) ?? hostingEnvironment.ApplicationVirtualPath; /// /// Return the Url for a Web Api service