Merge remote-tracking branch 'origin/netcore/netcore' into netcore/feature/ModelsBuilderEmbedded-migration-roslyn-compiler

This commit is contained in:
Bjarke Berg
2020-09-09 12:38:16 +02:00
6 changed files with 78 additions and 22 deletions

View File

@@ -7,5 +7,6 @@ namespace Umbraco.Core.Configuration
void RemoveConnectionString();
void SaveConnectionString(string connectionString, string providerName);
void SaveConfigValue(string itemPath, object value);
void SaveDisableRedirectUrlTracking(bool disable);
}
}

View File

@@ -2,8 +2,8 @@
using System.Configuration;
using System.IO;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
using Umbraco.Composing;
using Umbraco.Core.IO;
using Umbraco.Core.Logging;
@@ -111,6 +111,26 @@ namespace Umbraco.Core.Configuration
throw new NotImplementedException();
}
public void SaveDisableRedirectUrlTracking(bool disable)
{
var fileName = _ioHelper.MapPath("~/config/umbracoSettings.config");
var umbracoConfig = new XmlDocument { PreserveWhitespace = true };
umbracoConfig.Load(fileName);
var action = disable ? "disable" : "enable";
if (File.Exists(fileName) == false)
throw new Exception($"Couldn't {action} URL Tracker, the umbracoSettings.config file does not exist.");
if (!(umbracoConfig.SelectSingleNode("//web.routing") is XmlElement webRoutingElement))
throw new Exception($"Couldn't {action} URL Tracker, the web.routing element was not found in umbracoSettings.config.");
// note: this adds the attribute if it does not exist
webRoutingElement.SetAttribute("disableRedirectUrlTracking", disable.ToString().ToLowerInvariant());
umbracoConfig.Save(fileName);
}
private static void AddOrUpdateAttribute(XElement element, string name, string value)
{
var attribute = element.Attribute(name);