2020-05-13 14:49:00 +10:00
|
|
|
|
using System;
|
|
|
|
|
|
using Umbraco.Core;
|
|
|
|
|
|
using Microsoft.AspNetCore.Routing;
|
|
|
|
|
|
using System.Reflection;
|
2020-05-13 17:14:09 +10:00
|
|
|
|
using Umbraco.Web.Common.Install;
|
2020-05-18 15:16:09 +10:00
|
|
|
|
using Umbraco.Core.Hosting;
|
2020-05-13 14:49:00 +10:00
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Extensions
|
|
|
|
|
|
{
|
|
|
|
|
|
public static class LinkGeneratorExtensions
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Return the back office url if the back office is installed
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="url"></param>
|
|
|
|
|
|
/// <returns></returns>
|
2020-05-18 15:16:09 +10:00
|
|
|
|
public static string GetBackOfficeUrl(this LinkGenerator linkGenerator, IHostingEnvironment hostingEnvironment)
|
2020-05-13 14:49:00 +10:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
}
|
2020-05-18 15:15:53 +10:00
|
|
|
|
catch
|
2020-05-13 14:49:00 +10:00
|
|
|
|
{
|
2020-05-18 15:16:09 +10:00
|
|
|
|
return hostingEnvironment.ApplicationVirtualPath; // this would indicate that the installer is installed without the back office
|
2020-05-13 14:49:00 +10:00
|
|
|
|
}
|
2020-05-13 17:14:09 +10:00
|
|
|
|
|
2020-05-14 21:12:41 +10:00
|
|
|
|
return linkGenerator.GetPathByAction("Default", ControllerExtensions.GetControllerName(backOfficeControllerType), new { area = Constants.Web.Mvc.BackOfficeApiArea });
|
2020-05-13 14:49:00 +10:00
|
|
|
|
}
|
2020-05-13 17:14:09 +10:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Returns the URL for the installer
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="linkGenerator"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public static string GetInstallerUrl(this LinkGenerator linkGenerator)
|
|
|
|
|
|
{
|
2020-05-18 15:12:30 +10:00
|
|
|
|
return linkGenerator.GetPathByAction(nameof(InstallController.Index), ControllerExtensions.GetControllerName<InstallController>(), new { area = Constants.Web.Mvc.InstallArea });
|
2020-05-13 17:14:09 +10:00
|
|
|
|
}
|
2020-05-13 14:49:00 +10:00
|
|
|
|
}
|
|
|
|
|
|
}
|