From 8d936c08dacb91e719dae5cd404876ab2b26f156 Mon Sep 17 00:00:00 2001 From: Warren Buckley Date: Wed, 7 Jul 2021 12:52:02 +0100 Subject: [PATCH 1/5] Change RenderController defautl type to be swapped out using the .NETCore options pattern --- .../Routing/UmbracoRouteValuesFactoryTests.cs | 9 +++--- .../Controllers/UmbracoRenderingDefaults.cs | 14 ---------- ....cs => UmbracoRenderingDefaultsOptions.cs} | 4 +-- .../UmbracoRenderingDefaultsOptionsSetup.cs | 28 +++++++++++++++++++ .../UmbracoBuilderExtensions.cs | 5 +++- .../Routing/UmbracoRouteValuesFactory.cs | 7 ++--- 6 files changed, 42 insertions(+), 25 deletions(-) delete mode 100644 src/Umbraco.Web.Website/Controllers/UmbracoRenderingDefaults.cs rename src/Umbraco.Web.Website/Controllers/{IUmbracoRenderingDefaults.cs => UmbracoRenderingDefaultsOptions.cs} (72%) create mode 100644 src/Umbraco.Web.Website/Controllers/UmbracoRenderingDefaultsOptionsSetup.cs diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Web.Website/Routing/UmbracoRouteValuesFactoryTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Web.Website/Routing/UmbracoRouteValuesFactoryTests.cs index 2bd482b8eb..1e7d19e18f 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Web.Website/Routing/UmbracoRouteValuesFactoryTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Web.Website/Routing/UmbracoRouteValuesFactoryTests.cs @@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Mvc.Controllers; using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.Logging.Abstractions; +using Microsoft.Extensions.Options; using Moq; using NUnit.Framework; using Umbraco.Cms.Core.Features; @@ -29,7 +30,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Web.Website.Routing { private UmbracoRouteValuesFactory GetFactory( out Mock publishedRouter, - out UmbracoRenderingDefaults renderingDefaults, + out IOptions renderingDefaults, out IPublishedRequest request) { var builder = new PublishedRequestBuilder(new Uri("https://example.com"), Mock.Of()); @@ -41,7 +42,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Web.Website.Routing .Returns((IPublishedRequest r, IPublishedContent c) => Task.FromResult(builtRequest)) .Verifiable(); - renderingDefaults = new UmbracoRenderingDefaults(); + renderingDefaults = Mock.Of>(x => x.Value.DefaultControllerType == typeof(RenderController)); // add the default one var actionDescriptors = new List @@ -82,12 +83,12 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Web.Website.Routing [Test] public async Task Adds_Result_To_Route_Value_Dictionary() { - UmbracoRouteValuesFactory factory = GetFactory(out _, out UmbracoRenderingDefaults renderingDefaults, out IPublishedRequest request); + UmbracoRouteValuesFactory factory = GetFactory(out _, out IOptions renderingDefaults, out IPublishedRequest request); UmbracoRouteValues result = await factory.CreateAsync(new DefaultHttpContext(), request); Assert.IsNotNull(result); - Assert.AreEqual(renderingDefaults.DefaultControllerType, result.ControllerType); + Assert.AreEqual(renderingDefaults.Value.DefaultControllerType, result.ControllerType); Assert.AreEqual(UmbracoRouteValues.DefaultActionName, result.ActionName); Assert.IsNull(result.TemplateName); } diff --git a/src/Umbraco.Web.Website/Controllers/UmbracoRenderingDefaults.cs b/src/Umbraco.Web.Website/Controllers/UmbracoRenderingDefaults.cs deleted file mode 100644 index 095f57b631..0000000000 --- a/src/Umbraco.Web.Website/Controllers/UmbracoRenderingDefaults.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using Umbraco.Cms.Web.Common.Controllers; - -namespace Umbraco.Cms.Web.Website.Controllers -{ - /// - /// The defaults used for rendering Umbraco front-end pages - /// - public class UmbracoRenderingDefaults : IUmbracoRenderingDefaults - { - /// - public Type DefaultControllerType => typeof(RenderController); - } -} diff --git a/src/Umbraco.Web.Website/Controllers/IUmbracoRenderingDefaults.cs b/src/Umbraco.Web.Website/Controllers/UmbracoRenderingDefaultsOptions.cs similarity index 72% rename from src/Umbraco.Web.Website/Controllers/IUmbracoRenderingDefaults.cs rename to src/Umbraco.Web.Website/Controllers/UmbracoRenderingDefaultsOptions.cs index 6f4fdb0cb2..120d0f6099 100644 --- a/src/Umbraco.Web.Website/Controllers/IUmbracoRenderingDefaults.cs +++ b/src/Umbraco.Web.Website/Controllers/UmbracoRenderingDefaultsOptions.cs @@ -5,11 +5,11 @@ namespace Umbraco.Cms.Web.Website.Controllers /// /// The defaults used for rendering Umbraco front-end pages /// - public interface IUmbracoRenderingDefaults + public class UmbracoRenderingDefaultsOptions { /// /// Gets the default umbraco render controller type /// - Type DefaultControllerType { get; } + public Type DefaultControllerType { get; set; } } } diff --git a/src/Umbraco.Web.Website/Controllers/UmbracoRenderingDefaultsOptionsSetup.cs b/src/Umbraco.Web.Website/Controllers/UmbracoRenderingDefaultsOptionsSetup.cs new file mode 100644 index 0000000000..22b970dc92 --- /dev/null +++ b/src/Umbraco.Web.Website/Controllers/UmbracoRenderingDefaultsOptionsSetup.cs @@ -0,0 +1,28 @@ +using System; +using Microsoft.Extensions.Options; +using Umbraco.Cms.Web.Common.Controllers; + +namespace Umbraco.Cms.Web.Website.Controllers +{ + public class UmbracoRenderingDefaultsOptionsSetup : IConfigureOptions + { + //private IOptions _umbracoRenderingDefaultOptions; + + //public UmbracoRenderingDefaultsOptionsSetup(IOptions umbracoRenderingDefaultOptions) + //{ + // _umbracoRenderingDefaultOptions = umbracoRenderingDefaultOptions; + //} + + public void Configure(UmbracoRenderingDefaultsOptions options) + { + if (options == null) + { + throw new ArgumentNullException(nameof(options)); + } + + //options.DefaultControllerType = _umbracoRenderingDefaultOptions.Value.DefaultControllerType; + + options.DefaultControllerType = typeof(RenderController); + } + } +} diff --git a/src/Umbraco.Web.Website/DependencyInjection/UmbracoBuilderExtensions.cs b/src/Umbraco.Web.Website/DependencyInjection/UmbracoBuilderExtensions.cs index 69618004c7..3f050e5ad1 100644 --- a/src/Umbraco.Web.Website/DependencyInjection/UmbracoBuilderExtensions.cs +++ b/src/Umbraco.Web.Website/DependencyInjection/UmbracoBuilderExtensions.cs @@ -40,7 +40,10 @@ namespace Umbraco.Extensions builder.Services.AddScoped(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); - builder.Services.AddSingleton(); + + // Umbraco Rendering Defaults startup options to define which RenderController type to use + builder.Services.ConfigureOptions(); + builder.Services.AddSingleton(); builder.Services.AddSingleton(); diff --git a/src/Umbraco.Web.Website/Routing/UmbracoRouteValuesFactory.cs b/src/Umbraco.Web.Website/Routing/UmbracoRouteValuesFactory.cs index e1b85919f4..5cba399fba 100644 --- a/src/Umbraco.Web.Website/Routing/UmbracoRouteValuesFactory.cs +++ b/src/Umbraco.Web.Website/Routing/UmbracoRouteValuesFactory.cs @@ -2,6 +2,7 @@ using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Controllers; +using Microsoft.Extensions.Options; using Umbraco.Cms.Core.Features; using Umbraco.Cms.Core.Models.PublishedContent; using Umbraco.Cms.Core.Routing; @@ -18,7 +19,6 @@ namespace Umbraco.Cms.Web.Website.Routing /// public class UmbracoRouteValuesFactory : IUmbracoRouteValuesFactory { - private readonly IUmbracoRenderingDefaults _renderingDefaults; private readonly IShortStringHelper _shortStringHelper; private readonly UmbracoFeatures _umbracoFeatures; private readonly IControllerActionSearcher _controllerActionSearcher; @@ -30,18 +30,17 @@ namespace Umbraco.Cms.Web.Website.Routing /// Initializes a new instance of the class. /// public UmbracoRouteValuesFactory( - IUmbracoRenderingDefaults renderingDefaults, + IOptions renderingDefaults, IShortStringHelper shortStringHelper, UmbracoFeatures umbracoFeatures, IControllerActionSearcher controllerActionSearcher, IPublishedRouter publishedRouter) { - _renderingDefaults = renderingDefaults; _shortStringHelper = shortStringHelper; _umbracoFeatures = umbracoFeatures; _controllerActionSearcher = controllerActionSearcher; _publishedRouter = publishedRouter; - _defaultControllerName = new Lazy(() => ControllerExtensions.GetControllerName(_renderingDefaults.DefaultControllerType)); + _defaultControllerName = new Lazy(() => ControllerExtensions.GetControllerName(renderingDefaults.Value.DefaultControllerType)); _defaultControllerDescriptor = new Lazy(() => { ControllerActionDescriptor descriptor = _controllerActionSearcher.Find( From b177c1ba12b158d1322b905fb2582668c981a33e Mon Sep 17 00:00:00 2001 From: Warren Buckley Date: Wed, 7 Jul 2021 13:07:01 +0100 Subject: [PATCH 2/5] Further Simplification of IOptions --- .../UmbracoRenderingDefaultsOptions.cs | 3 +- .../UmbracoRenderingDefaultsOptionsSetup.cs | 28 ------------------- .../UmbracoBuilderExtensions.cs | 2 +- 3 files changed, 3 insertions(+), 30 deletions(-) delete mode 100644 src/Umbraco.Web.Website/Controllers/UmbracoRenderingDefaultsOptionsSetup.cs diff --git a/src/Umbraco.Web.Website/Controllers/UmbracoRenderingDefaultsOptions.cs b/src/Umbraco.Web.Website/Controllers/UmbracoRenderingDefaultsOptions.cs index 120d0f6099..fb9f02d385 100644 --- a/src/Umbraco.Web.Website/Controllers/UmbracoRenderingDefaultsOptions.cs +++ b/src/Umbraco.Web.Website/Controllers/UmbracoRenderingDefaultsOptions.cs @@ -1,4 +1,5 @@ using System; +using Umbraco.Cms.Web.Common.Controllers; namespace Umbraco.Cms.Web.Website.Controllers { @@ -10,6 +11,6 @@ namespace Umbraco.Cms.Web.Website.Controllers /// /// Gets the default umbraco render controller type /// - public Type DefaultControllerType { get; set; } + public Type DefaultControllerType { get; set; } = typeof(RenderController); } } diff --git a/src/Umbraco.Web.Website/Controllers/UmbracoRenderingDefaultsOptionsSetup.cs b/src/Umbraco.Web.Website/Controllers/UmbracoRenderingDefaultsOptionsSetup.cs deleted file mode 100644 index 22b970dc92..0000000000 --- a/src/Umbraco.Web.Website/Controllers/UmbracoRenderingDefaultsOptionsSetup.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using Microsoft.Extensions.Options; -using Umbraco.Cms.Web.Common.Controllers; - -namespace Umbraco.Cms.Web.Website.Controllers -{ - public class UmbracoRenderingDefaultsOptionsSetup : IConfigureOptions - { - //private IOptions _umbracoRenderingDefaultOptions; - - //public UmbracoRenderingDefaultsOptionsSetup(IOptions umbracoRenderingDefaultOptions) - //{ - // _umbracoRenderingDefaultOptions = umbracoRenderingDefaultOptions; - //} - - public void Configure(UmbracoRenderingDefaultsOptions options) - { - if (options == null) - { - throw new ArgumentNullException(nameof(options)); - } - - //options.DefaultControllerType = _umbracoRenderingDefaultOptions.Value.DefaultControllerType; - - options.DefaultControllerType = typeof(RenderController); - } - } -} diff --git a/src/Umbraco.Web.Website/DependencyInjection/UmbracoBuilderExtensions.cs b/src/Umbraco.Web.Website/DependencyInjection/UmbracoBuilderExtensions.cs index 3f050e5ad1..098388df70 100644 --- a/src/Umbraco.Web.Website/DependencyInjection/UmbracoBuilderExtensions.cs +++ b/src/Umbraco.Web.Website/DependencyInjection/UmbracoBuilderExtensions.cs @@ -42,7 +42,7 @@ namespace Umbraco.Extensions builder.Services.AddSingleton(); // Umbraco Rendering Defaults startup options to define which RenderController type to use - builder.Services.ConfigureOptions(); + builder.Services.ConfigureOptions(); builder.Services.AddSingleton(); From 28b0e108e42b67371197b1f12262f6c6a85ca55c Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Wed, 7 Jul 2021 14:51:05 +0200 Subject: [PATCH 3/5] Update src/Umbraco.Web.Website/DependencyInjection/UmbracoBuilderExtensions.cs --- .../DependencyInjection/UmbracoBuilderExtensions.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Umbraco.Web.Website/DependencyInjection/UmbracoBuilderExtensions.cs b/src/Umbraco.Web.Website/DependencyInjection/UmbracoBuilderExtensions.cs index 098388df70..59905e5626 100644 --- a/src/Umbraco.Web.Website/DependencyInjection/UmbracoBuilderExtensions.cs +++ b/src/Umbraco.Web.Website/DependencyInjection/UmbracoBuilderExtensions.cs @@ -40,10 +40,6 @@ namespace Umbraco.Extensions builder.Services.AddScoped(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); - - // Umbraco Rendering Defaults startup options to define which RenderController type to use - builder.Services.ConfigureOptions(); - builder.Services.AddSingleton(); builder.Services.AddSingleton(); From 9a7f233a904bbc6c8935891fa65e51f2c45d266b Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Wed, 7 Jul 2021 15:55:33 +0200 Subject: [PATCH 4/5] Migrated surfaceaction extension methods --- .../Extensions/FriendlyUrlHelperExtensions.cs | 50 +++++++++++++++++++ .../Extensions/UrlHelperExtensions.cs | 50 +++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 src/Umbraco.Web.Common/Extensions/FriendlyUrlHelperExtensions.cs diff --git a/src/Umbraco.Web.Common/Extensions/FriendlyUrlHelperExtensions.cs b/src/Umbraco.Web.Common/Extensions/FriendlyUrlHelperExtensions.cs new file mode 100644 index 0000000000..0340ce7a50 --- /dev/null +++ b/src/Umbraco.Web.Common/Extensions/FriendlyUrlHelperExtensions.cs @@ -0,0 +1,50 @@ +using Microsoft.AspNetCore.DataProtection; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.DependencyInjection; +using Umbraco.Cms.Core.Web; +using Umbraco.Cms.Web.Common.DependencyInjection; + +namespace Umbraco.Extensions +{ + public static class FriendlyUrlHelperExtensions + { + + private static IUmbracoContext UmbracoContext { get; } = + StaticServiceProvider.Instance.GetRequiredService().GetRequiredUmbracoContext(); + + private static IDataProtectionProvider DataProtectionProvider { get; } = + StaticServiceProvider.Instance.GetRequiredService(); + /// + /// Generates a URL based on the current Umbraco URL with a custom query string that will route to the specified SurfaceController + /// + /// + /// + /// + /// + public static string SurfaceAction(this IUrlHelper url, string action, string controllerName) + => UrlHelperExtensions.SurfaceAction(url, UmbracoContext, DataProtectionProvider, action, controllerName); + + /// + /// Generates a URL based on the current Umbraco URL with a custom query string that will route to the specified SurfaceController + /// + /// + /// + /// + /// + /// + public static string SurfaceAction(this IUrlHelper url, string action, string controllerName, object additionalRouteVals) + => UrlHelperExtensions.SurfaceAction(url, UmbracoContext, DataProtectionProvider, action, controllerName, additionalRouteVals); + + /// + /// Generates a URL based on the current Umbraco URL with a custom query string that will route to the specified SurfaceController + /// + /// + /// + /// + /// + /// + /// + public static string SurfaceAction(this IUrlHelper url, string action, string controllerName, string area, object additionalRouteVals) + => UrlHelperExtensions.SurfaceAction(url, UmbracoContext, DataProtectionProvider, action, controllerName, area, additionalRouteVals); + } +} diff --git a/src/Umbraco.Web.Common/Extensions/UrlHelperExtensions.cs b/src/Umbraco.Web.Common/Extensions/UrlHelperExtensions.cs index d3fd3bddba..fb2a272585 100644 --- a/src/Umbraco.Web.Common/Extensions/UrlHelperExtensions.cs +++ b/src/Umbraco.Web.Common/Extensions/UrlHelperExtensions.cs @@ -1,8 +1,10 @@ using System; +using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Linq.Expressions; using System.Web; +using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.Html; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Routing; @@ -12,8 +14,10 @@ using Umbraco.Cms.Core.Hosting; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Models.PublishedContent; using Umbraco.Cms.Core.PropertyEditors.ValueConverters; +using Umbraco.Cms.Core.Web; using Umbraco.Cms.Core.WebAssets; using Umbraco.Cms.Web.Common.Controllers; +using Umbraco.Cms.Web.Common.Security; namespace Umbraco.Extensions { @@ -280,5 +284,51 @@ namespace Umbraco.Extensions return htmlEncode ? new HtmlString(HttpUtility.HtmlEncode(url)) : new HtmlString(url); } + /// + /// Generates a URL based on the current Umbraco URL with a custom query string that will route to the specified SurfaceController + /// + /// + /// + /// + /// + public static string SurfaceAction(this IUrlHelper url, IUmbracoContext umbracoContext, IDataProtectionProvider dataProtectionProvider,string action, string controllerName) + { + return url.SurfaceAction(umbracoContext, dataProtectionProvider, action, controllerName, null); + } + + /// + /// Generates a URL based on the current Umbraco URL with a custom query string that will route to the specified SurfaceController + /// + /// + /// + /// + /// + /// + public static string SurfaceAction(this IUrlHelper url, IUmbracoContext umbracoContext, IDataProtectionProvider dataProtectionProvider,string action, string controllerName, object additionalRouteVals) + { + return url.SurfaceAction(umbracoContext, dataProtectionProvider, action, controllerName, "", additionalRouteVals); + } + + /// + /// Generates a URL based on the current Umbraco URL with a custom query string that will route to the specified SurfaceController + /// + /// + /// + /// + /// + /// + /// + public static string SurfaceAction(this IUrlHelper url, IUmbracoContext umbracoContext, IDataProtectionProvider dataProtectionProvider, string action, string controllerName, string area, object additionalRouteVals) + { + if (action == null) throw new ArgumentNullException(nameof(action)); + if (string.IsNullOrEmpty(action)) throw new ArgumentException("Value can't be empty.", nameof(action)); + if (controllerName == null) throw new ArgumentNullException(nameof(controllerName)); + if (string.IsNullOrEmpty(controllerName)) throw new ArgumentException("Value can't be empty.", nameof(controllerName)); + + var encryptedRoute = EncryptionHelper.CreateEncryptedRouteString(dataProtectionProvider, controllerName, action, area, additionalRouteVals); + + var result = umbracoContext.OriginalRequestUrl.AbsolutePath.EnsureEndsWith('?') + "ufprt=" + encryptedRoute; + return result; + } } } From 414b0037471941d7826eaa794b85c9d878025a37 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Wed, 7 Jul 2021 15:58:16 +0200 Subject: [PATCH 5/5] uncomment old file --- src/Umbraco.Web/UrlHelperRenderExtensions.cs | 166 +++++++++---------- 1 file changed, 83 insertions(+), 83 deletions(-) diff --git a/src/Umbraco.Web/UrlHelperRenderExtensions.cs b/src/Umbraco.Web/UrlHelperRenderExtensions.cs index d1eb46a2b8..70a414ff29 100644 --- a/src/Umbraco.Web/UrlHelperRenderExtensions.cs +++ b/src/Umbraco.Web/UrlHelperRenderExtensions.cs @@ -261,52 +261,52 @@ namespace Umbraco.Web // // #endregion - /// - /// Generates a URL based on the current Umbraco URL with a custom query string that will route to the specified SurfaceController - /// - /// - /// - /// - /// - public static string SurfaceAction(this UrlHelper url, string action, string controllerName) - { - return url.SurfaceAction(action, controllerName, null); - } - - /// - /// Generates a URL based on the current Umbraco URL with a custom query string that will route to the specified SurfaceController - /// - /// - /// - /// - /// - /// - public static string SurfaceAction(this UrlHelper url, string action, string controllerName, object additionalRouteVals) - { - return url.SurfaceAction(action, controllerName, "", additionalRouteVals); - } - - /// - /// Generates a URL based on the current Umbraco URL with a custom query string that will route to the specified SurfaceController - /// - /// - /// - /// - /// - /// - /// - public static string SurfaceAction(this UrlHelper url, string action, string controllerName, string area, object additionalRouteVals) - { - if (action == null) throw new ArgumentNullException(nameof(action)); - if (string.IsNullOrEmpty(action)) throw new ArgumentException("Value can't be empty.", nameof(action)); - if (controllerName == null) throw new ArgumentNullException(nameof(controllerName)); - if (string.IsNullOrEmpty(controllerName)) throw new ArgumentException("Value can't be empty.", nameof(controllerName)); - - var encryptedRoute = CreateEncryptedRouteString(controllerName, action, area, additionalRouteVals); - - var result = Current.UmbracoContext.OriginalRequestUrl.AbsolutePath.EnsureEndsWith('?') + "ufprt=" + encryptedRoute; - return result; - } + // /// + // /// Generates a URL based on the current Umbraco URL with a custom query string that will route to the specified SurfaceController + // /// + // /// + // /// + // /// + // /// + // public static string SurfaceAction(this UrlHelper url, string action, string controllerName) + // { + // return url.SurfaceAction(action, controllerName, null); + // } + // + // /// + // /// Generates a URL based on the current Umbraco URL with a custom query string that will route to the specified SurfaceController + // /// + // /// + // /// + // /// + // /// + // /// + // public static string SurfaceAction(this UrlHelper url, string action, string controllerName, object additionalRouteVals) + // { + // return url.SurfaceAction(action, controllerName, "", additionalRouteVals); + // } + // + // /// + // /// Generates a URL based on the current Umbraco URL with a custom query string that will route to the specified SurfaceController + // /// + // /// + // /// + // /// + // /// + // /// + // /// + // public static string SurfaceAction(this UrlHelper url, string action, string controllerName, string area, object additionalRouteVals) + // { + // if (action == null) throw new ArgumentNullException(nameof(action)); + // if (string.IsNullOrEmpty(action)) throw new ArgumentException("Value can't be empty.", nameof(action)); + // if (controllerName == null) throw new ArgumentNullException(nameof(controllerName)); + // if (string.IsNullOrEmpty(controllerName)) throw new ArgumentException("Value can't be empty.", nameof(controllerName)); + // + // var encryptedRoute = CreateEncryptedRouteString(controllerName, action, area, additionalRouteVals); + // + // var result = Current.UmbracoContext.OriginalRequestUrl.AbsolutePath.EnsureEndsWith('?') + "ufprt=" + encryptedRoute; + // return result; + // } //TODO Move to LinkGenerator // /// @@ -384,42 +384,42 @@ namespace Umbraco.Web // return url.SurfaceAction(action, typeof (T), additionalRouteVals); // } - /// - /// This is used in methods like BeginUmbracoForm and SurfaceAction to generate an encrypted string which gets submitted in a request for which - /// Umbraco can decrypt during the routing process in order to delegate the request to a specific MVC Controller. - /// - /// - /// - /// - /// - /// - internal static string CreateEncryptedRouteString(string controllerName, string controllerAction, string area, object additionalRouteVals = null) - { - if (controllerName == null) throw new ArgumentNullException(nameof(controllerName)); - if (string.IsNullOrEmpty(controllerName)) throw new ArgumentException("Value can't be empty.", nameof(controllerName)); - if (controllerAction == null) throw new ArgumentNullException(nameof(controllerAction)); - if (string.IsNullOrEmpty(controllerAction)) throw new ArgumentException("Value can't be empty.", nameof(controllerAction)); - if (area == null) throw new ArgumentNullException(nameof(area)); - - //need to create a params string as Base64 to put into our hidden field to use during the routes - var surfaceRouteParams = $"c={HttpUtility.UrlEncode(controllerName)}&a={HttpUtility.UrlEncode(controllerAction)}&ar={area}"; - - //checking if the additional route values is already a dictionary and convert to querystring - string additionalRouteValsAsQuery; - if (additionalRouteVals != null) - { - if (additionalRouteVals is Dictionary additionalRouteValsAsDictionary) - additionalRouteValsAsQuery = additionalRouteValsAsDictionary.ToQueryString(); - else - additionalRouteValsAsQuery = additionalRouteVals.ToDictionary().ToQueryString(); - } - else - additionalRouteValsAsQuery = null; - - if (additionalRouteValsAsQuery.IsNullOrWhiteSpace() == false) - surfaceRouteParams += "&" + additionalRouteValsAsQuery; - - return surfaceRouteParams.EncryptWithMachineKey(); - } + // /// + // /// This is used in methods like BeginUmbracoForm and SurfaceAction to generate an encrypted string which gets submitted in a request for which + // /// Umbraco can decrypt during the routing process in order to delegate the request to a specific MVC Controller. + // /// + // /// + // /// + // /// + // /// + // /// + // internal static string CreateEncryptedRouteString(string controllerName, string controllerAction, string area, object additionalRouteVals = null) + // { + // if (controllerName == null) throw new ArgumentNullException(nameof(controllerName)); + // if (string.IsNullOrEmpty(controllerName)) throw new ArgumentException("Value can't be empty.", nameof(controllerName)); + // if (controllerAction == null) throw new ArgumentNullException(nameof(controllerAction)); + // if (string.IsNullOrEmpty(controllerAction)) throw new ArgumentException("Value can't be empty.", nameof(controllerAction)); + // if (area == null) throw new ArgumentNullException(nameof(area)); + // + // //need to create a params string as Base64 to put into our hidden field to use during the routes + // var surfaceRouteParams = $"c={HttpUtility.UrlEncode(controllerName)}&a={HttpUtility.UrlEncode(controllerAction)}&ar={area}"; + // + // //checking if the additional route values is already a dictionary and convert to querystring + // string additionalRouteValsAsQuery; + // if (additionalRouteVals != null) + // { + // if (additionalRouteVals is Dictionary additionalRouteValsAsDictionary) + // additionalRouteValsAsQuery = additionalRouteValsAsDictionary.ToQueryString(); + // else + // additionalRouteValsAsQuery = additionalRouteVals.ToDictionary().ToQueryString(); + // } + // else + // additionalRouteValsAsQuery = null; + // + // if (additionalRouteValsAsQuery.IsNullOrWhiteSpace() == false) + // surfaceRouteParams += "&" + additionalRouteValsAsQuery; + // + // return surfaceRouteParams.EncryptWithMachineKey(); + // } } }