This is the fourth part of the Sitefinity series. For your convenience you can find other parts in the table of contents in Sitefinity Part 1 — Capturing logs
Last time we saw how to change database connection string for Sitefinity which can be useful if we need to extract it in runtime. In the same manner we can enable Redis which is required when running Sitefinity in Azure (and is not needed on developer machine). First, add code to AssemblyInfo.cs
:
1 2 3 |
// Sitefinity version: 10.0.6411.0 // Override configuration files [assembly: PreApplicationStartMethod(typeof(LoadBalancerConfiguration), "OverrideConnectionString")] |
And now modify file SystemConfig.config
with Redis settings:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
using System.IO; using System.Web.Hosting; using System.Xml.Linq; namespace Cms { public class LoadBalancerConfiguration { public static void OverrideConnectionString() { var configurationFilePath = HostingEnvironment.MapPath("~/App_Data/Sitefinity/Configuration/SystemConfig.config"); if (string.IsNullOrEmpty(config.RedisConnectionString)) { return; } var document = XDocument.Load(configurationFilePath); var systemConfig = document.Element("systemConfig"); var loadBalancingConfig = systemConfig.Element("loadBalancingConfig"); if (loadBalancingConfig == null) { loadBalancingConfig = new XElement("loadBalancingConfig"); systemConfig.Add(loadBalancingConfig); } var redisSettings = loadBalancingConfig.Element("redisSettings"); if (redisSettings == null) { redisSettings = new XElement("redisSettings"); loadBalancingConfig.Add(redisSettings); } var connectionString = redisSettings.Attribute("ConnectionString"); if (connectionString == null) { connectionString = new XAttribute("ConnectionString", ""); redisSettings.Add(connectionString); } connectionString.Value = "YOUR_CONNECTION_STRING"; File.WriteAllText(configurationFilePath, document.ToString()); } } } |
Tested with Sitefinity version: 10.0.6411.0.