Skip to content

Commit

Permalink
Fix deploy Umbraco as a child IIS application not working umbraco#11891
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Tkacul committed Dec 21, 2022
1 parent 5f7df5b commit 659171f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 125 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Umbraco.Cms.Web.BackOffice.Install;
using Umbraco.Cms.Web.Common.Routing;
using static Microsoft.AspNetCore.Routing.ControllerLinkGeneratorExtensions;
using Constants = Umbraco.Cms.Core.Constants;
using static Microsoft.AspNetCore.Routing.ControllerLinkGeneratorExtensions;
namespace Umbraco.Extensions;

public static class BackofficeUmbracoLinkGeneratorExtensions
Expand Down
132 changes: 8 additions & 124 deletions src/Umbraco.Web.Common/Extensions/LinkGeneratorExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,28 +189,8 @@ public static class LinkGeneratorExtensions
[Obsolete("Please use Umbraco.Cms.Web.Common.Routing.LinkGenerator instead.")]
public static string? GetBackOfficeUrl(this Microsoft.AspNetCore.Routing.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
}

LinkGenerator umbracoLinkGenerator = StaticServiceProvider.Instance.GetRequiredService<LinkGenerator>();
return umbracoLinkGenerator.GetPathByAction(
"Default",
ControllerExtensions.GetControllerName(backOfficeControllerType),
new { area = Constants.Web.Mvc.BackOfficeApiArea });
return umbracoLinkGenerator.GetBackOfficeUrl(hostingEnvironment);
}

/// <summary>
Expand All @@ -222,19 +202,16 @@ public static class LinkGeneratorExtensions
where T : UmbracoApiControllerBase
{
LinkGenerator umbracoLinkGenerator = StaticServiceProvider.Instance.GetRequiredService<LinkGenerator>();
return umbracoLinkGenerator.GetUmbracoControllerUrl(actionName, typeof(T), new Dictionary<string, object?>
{
["id"] = id
});
return umbracoLinkGenerator.GetUmbracoApiService<T>(actionName, id);
}

[Obsolete("Please use Umbraco.Cms.Web.Common.Routing.LinkGenerator instead.")]
public static string? GetUmbracoApiService<T>(this Microsoft.AspNetCore.Routing.LinkGenerator linkGenerator,
string actionName, IDictionary<string, object?>? values)
where T : UmbracoApiControllerBase
{
LinkGenerator umbracoLinkGenerator = StaticServiceProvider.Instance.GetRequiredService<LinkGenerator>();
return umbracoLinkGenerator.GetUmbracoControllerUrl(actionName, typeof(T), values);
return umbracoLinkGenerator.GetUmbracoApiService<T>(actionName, values);
}

[Obsolete("Please use Umbraco.Cms.Web.Common.Routing.LinkGenerator instead.")]
Expand All @@ -244,14 +221,7 @@ public static class LinkGeneratorExtensions
where T : UmbracoApiControllerBase
{
LinkGenerator umbracoLinkGenerator = StaticServiceProvider.Instance.GetRequiredService<LinkGenerator>();
MethodInfo? method = ExpressionHelper.GetMethodInfo(methodSelector);
if (method == null)
{
throw new MissingMethodException("Could not find the method " + methodSelector + " on type " + typeof(T) +
" or the result ");
}

return umbracoLinkGenerator.GetUmbracoApiService<T>(method.Name)?.TrimEnd(method.Name);
return umbracoLinkGenerator.GetUmbracoApiServiceBaseUrl<T>(methodSelector);
}

/// <summary>
Expand All @@ -260,50 +230,8 @@ public static class LinkGeneratorExtensions
[Obsolete("Please use Umbraco.Cms.Web.Common.Routing.LinkGenerator instead.")]
public static string? GetUmbracoControllerUrl(this Microsoft.AspNetCore.Routing.LinkGenerator linkGenerator, string actionName, string controllerName, string? area, IDictionary<string, object?>? dict = null)
{
if (actionName == null)
{
throw new ArgumentNullException(nameof(actionName));
}

if (string.IsNullOrWhiteSpace(actionName))
{
throw new ArgumentException(
"Value can't be empty or consist only of white-space characters.",
nameof(actionName));
}

if (controllerName == null)
{
throw new ArgumentNullException(nameof(controllerName));
}

if (string.IsNullOrWhiteSpace(controllerName))
{
throw new ArgumentException(
"Value can't be empty or consist only of white-space characters.",
nameof(controllerName));
}

if (dict is null)
{
dict = new Dictionary<string, object?>();
}

if (!area.IsNullOrWhiteSpace())
{
dict["area"] = area!;
}

IDictionary<string, object?> values = dict.Aggregate(
new ExpandoObject() as IDictionary<string, object?>,
(a, p) =>
{
a.Add(p.Key, p.Value);
return a;
});

LinkGenerator umbracoLinkGenerator = StaticServiceProvider.Instance.GetRequiredService<LinkGenerator>();
return umbracoLinkGenerator.GetPathByAction(actionName, controllerName, values);
return umbracoLinkGenerator.GetUmbracoControllerUrl(actionName, controllerName, area, dict);
}

/// <summary>
Expand All @@ -312,39 +240,8 @@ public static class LinkGeneratorExtensions
[Obsolete("Please use Umbraco.Cms.Web.Common.Routing.LinkGenerator instead.")]
public static string? GetUmbracoControllerUrl(this Microsoft.AspNetCore.Routing.LinkGenerator linkGenerator, string actionName, Type controllerType, IDictionary<string, object?>? values = null)
{
if (actionName == null)
{
throw new ArgumentNullException(nameof(actionName));
}

if (string.IsNullOrWhiteSpace(actionName))
{
throw new ArgumentException(
"Value can't be empty or consist only of white-space characters.",
nameof(actionName));
}

if (controllerType == null)
{
throw new ArgumentNullException(nameof(controllerType));
}

var area = string.Empty;

if (!typeof(ControllerBase).IsAssignableFrom(controllerType))
{
throw new InvalidOperationException($"The controller {controllerType} is of type {typeof(ControllerBase)}");
}

PluginControllerMetadata metaData = PluginController.GetMetadata(controllerType);
if (metaData.AreaName.IsNullOrWhiteSpace() == false)
{
// set the area to the plugin area
area = metaData.AreaName;
}

LinkGenerator umbracoLinkGenerator = StaticServiceProvider.Instance.GetRequiredService<LinkGenerator>();
return umbracoLinkGenerator.GetUmbracoControllerUrl(actionName, ControllerExtensions.GetControllerName(controllerType), area, values);
return umbracoLinkGenerator.GetUmbracoControllerUrl(actionName, controllerType, values);
}

[Obsolete("Please use Umbraco.Cms.Web.Common.Routing.LinkGenerator instead.")]
Expand All @@ -353,20 +250,7 @@ public static class LinkGeneratorExtensions
Expression<Func<T, object>> methodSelector)
where T : UmbracoApiController
{
MethodInfo? method = ExpressionHelper.GetMethodInfo(methodSelector);
IDictionary<string, object?>? methodParams = ExpressionHelper.GetMethodParams(methodSelector);
if (method == null)
{
throw new MissingMethodException(
$"Could not find the method {methodSelector} on type {typeof(T)} or the result ");
}

if (methodParams?.Any() == false)
{
return linkGenerator.GetUmbracoApiService<T>(method.Name);
}

LinkGenerator umbracoLinkGenerator = StaticServiceProvider.Instance.GetRequiredService<LinkGenerator>();
return umbracoLinkGenerator.GetUmbracoApiService<T>(method.Name, methodParams);
return umbracoLinkGenerator.GetUmbracoApiService<T>(methodSelector);
}
}

0 comments on commit 659171f

Please sign in to comment.