From 85a3abf6431cd2852bd9c7dab315697614f876bb Mon Sep 17 00:00:00 2001 From: Sebastiaan Janssen Date: Wed, 3 Aug 2016 17:54:21 +0200 Subject: [PATCH] Adds a setting to be able to disable redirect URL tracking --- .../UmbracoSettings/IWebRoutingSection.cs | 2 + .../UmbracoSettings/WebRoutingElement.cs | 6 +++ .../WebRoutingElementDefaultTests.cs | 6 +++ .../Redirects/RedirectTrackingEventHandler.cs | 40 +++++++++++-------- 4 files changed, 38 insertions(+), 16 deletions(-) diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/IWebRoutingSection.cs b/src/Umbraco.Core/Configuration/UmbracoSettings/IWebRoutingSection.cs index 2998fc2f78..9eb6d02aa7 100644 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/IWebRoutingSection.cs +++ b/src/Umbraco.Core/Configuration/UmbracoSettings/IWebRoutingSection.cs @@ -9,6 +9,8 @@ bool DisableAlternativeTemplates { get; } bool DisableFindContentByIdPath { get; } + + bool DisableRedirectUrlTracking { get; } string UrlProviderMode { get; } diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/WebRoutingElement.cs b/src/Umbraco.Core/Configuration/UmbracoSettings/WebRoutingElement.cs index 1ed9bc034c..82f5d46b28 100644 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/WebRoutingElement.cs +++ b/src/Umbraco.Core/Configuration/UmbracoSettings/WebRoutingElement.cs @@ -27,6 +27,12 @@ namespace Umbraco.Core.Configuration.UmbracoSettings get { return (bool) base["disableFindContentByIdPath"]; } } + [ConfigurationProperty("disableRedirectUrlTracking", DefaultValue = "false")] + public bool DisableRedirectUrlTracking + { + get { return (bool) base["disableRedirectUrlTracking"]; } + } + [ConfigurationProperty("urlProviderMode", DefaultValue = "AutoLegacy")] public string UrlProviderMode { diff --git a/src/Umbraco.Tests/Configurations/UmbracoSettings/WebRoutingElementDefaultTests.cs b/src/Umbraco.Tests/Configurations/UmbracoSettings/WebRoutingElementDefaultTests.cs index 47b5e15b69..1e568c608e 100644 --- a/src/Umbraco.Tests/Configurations/UmbracoSettings/WebRoutingElementDefaultTests.cs +++ b/src/Umbraco.Tests/Configurations/UmbracoSettings/WebRoutingElementDefaultTests.cs @@ -28,5 +28,11 @@ namespace Umbraco.Tests.Configurations.UmbracoSettings { Assert.IsTrue(SettingsSection.WebRouting.DisableFindContentByIdPath == false); } + + [Test] + public void DisableRedirectUrlTracking() + { + Assert.IsTrue(SettingsSection.WebRouting.DisableRedirectUrlTracking == false); + } } } \ No newline at end of file diff --git a/src/Umbraco.Web/Redirects/RedirectTrackingEventHandler.cs b/src/Umbraco.Web/Redirects/RedirectTrackingEventHandler.cs index 42c5e6093b..82c06ca7d5 100644 --- a/src/Umbraco.Web/Redirects/RedirectTrackingEventHandler.cs +++ b/src/Umbraco.Web/Redirects/RedirectTrackingEventHandler.cs @@ -8,6 +8,7 @@ using Umbraco.Web.Routing; using System.Collections.Generic; using System.Linq; using Umbraco.Core.Cache; +using Umbraco.Core.Configuration; using Umbraco.Core.Models.PublishedContent; using Umbraco.Web.Cache; @@ -30,24 +31,31 @@ namespace Umbraco.Web.Redirects /// protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) { - // if any of these dlls are loaded we don't want to run our finder - var dlls = new[] + if (UmbracoConfig.For.UmbracoSettings().WebRouting.DisableRedirectUrlTracking) { - "InfoCaster.Umbraco.UrlTracker", - "SEOChecker", - "Simple301", - "Terabyte.Umbraco.Modules.PermanentRedirect", - "CMUmbracoTools", - "PWUrlRedirect" - }; - - // assuming all assemblies have been loaded already - // check if any of them matches one of the above dlls - var found = AppDomain.CurrentDomain.GetAssemblies() - .Select(x => x.FullName.Split(',')[0]) - .Any(x => dlls.Contains(x)); - if (found) ContentFinderResolver.Current.RemoveType(); + } + else + { + // if any of these dlls are loaded we don't want to run our finder + var dlls = new[] + { + "InfoCaster.Umbraco.UrlTracker", + "SEOChecker", + "Simple301", + "Terabyte.Umbraco.Modules.PermanentRedirect", + "CMUmbracoTools", + "PWUrlRedirect" + }; + + // assuming all assemblies have been loaded already + // check if any of them matches one of the above dlls + var found = AppDomain.CurrentDomain.GetAssemblies() + .Select(x => x.FullName.Split(',')[0]) + .Any(x => dlls.Contains(x)); + if (found) + ContentFinderResolver.Current.RemoveType(); + } } ///