From 868c9d02df2905ea3e38ac325ee3ae48d542bd0d Mon Sep 17 00:00:00 2001 From: Shannon Date: Wed, 16 Dec 2020 16:39:06 +1100 Subject: [PATCH] Fixes routing when installer needs to run --- .../Routing/UmbracoRouteValueTransformer.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Web.Website/Routing/UmbracoRouteValueTransformer.cs b/src/Umbraco.Web.Website/Routing/UmbracoRouteValueTransformer.cs index c41f34acc6..731c0320d6 100644 --- a/src/Umbraco.Web.Website/Routing/UmbracoRouteValueTransformer.cs +++ b/src/Umbraco.Web.Website/Routing/UmbracoRouteValueTransformer.cs @@ -48,6 +48,7 @@ namespace Umbraco.Web.Website.Routing private readonly IPublishedRouter _publishedRouter; private readonly GlobalSettings _globalSettings; private readonly IHostingEnvironment _hostingEnvironment; + private readonly IRuntimeState _runtime; /// /// Initializes a new instance of the class. @@ -60,7 +61,8 @@ namespace Umbraco.Web.Website.Routing IActionDescriptorCollectionProvider actionDescriptorCollectionProvider, IPublishedRouter publishedRouter, IOptions globalSettings, - IHostingEnvironment hostingEnvironment) + IHostingEnvironment hostingEnvironment, + IRuntimeState runtime) { _logger = logger; _umbracoContextAccessor = umbracoContextAccessor; @@ -70,16 +72,22 @@ namespace Umbraco.Web.Website.Routing _publishedRouter = publishedRouter; _globalSettings = globalSettings.Value; _hostingEnvironment = hostingEnvironment; + _runtime = runtime; } /// public override async ValueTask TransformAsync(HttpContext httpContext, RouteValueDictionary values) { + // If we aren't running, then we have nothing to route + if (_runtime.Level != RuntimeLevel.Run) + { + return values; + } + // will be null for any client side requests like JS, etc... if (_umbracoContextAccessor.UmbracoContext == null) { return values; - // throw new InvalidOperationException($"There is no current UmbracoContext, it must be initialized before the {nameof(UmbracoRouteValueTransformer)} executes, ensure that {nameof(UmbracoRequestMiddleware)} is registered prior to 'UseRouting'"); } // Check for back office request