using System; using Umbraco.Core; using Microsoft.AspNetCore.Routing; using System.Reflection; using Umbraco.Web.Common.Install; namespace Umbraco.Extensions { public static class LinkGeneratorExtensions { /// /// Return the back office url if the back office is installed /// /// /// public static string GetBackOfficeUrl(this LinkGenerator linkGenerator) { 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 (Exception) { return "/"; // this would indicate that the installer is installed without the back office } return linkGenerator.GetPathByAction("Default", ControllerExtensions.GetControllerName(backOfficeControllerType), new { area = Constants.Web.Mvc.BackOfficeArea }); } /// /// Returns the URL for the installer /// /// /// public static string GetInstallerUrl(this LinkGenerator linkGenerator) { return linkGenerator.GetPathByAction("Index", ControllerExtensions.GetControllerName(), new { area = Constants.Web.Mvc.InstallArea }); } } }