Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mitch 44 posts 159 karma points
    Jun 08, 2016 @ 10:24
    Mitch
    0

    Customising the path to umbraco.config

    Hi

    Is there a way to customise the path to the umbraco.config file for reading/writing?

    I know there is the umbracoContentXML setting that can be used in the web.config, but I need a way to set this path based on a variable that changes depending on the machine it is deployed to.

    Thanks in advance.

  • Simon Dingley 1474 posts 3431 karma points c-trib
    Jun 09, 2016 @ 11:03
    Simon Dingley
    1

    web.config Transformation?

    https://msdn.microsoft.com/en-us/library/dd465326(v=vs.110).aspx

    You could set up one for each environment you plan to deploy to since you would likely also have to also update things like the database connection string.

    Simon

  • Mitch 44 posts 159 karma points
    Jun 13, 2016 @ 13:54
    Mitch
    100

    Hi Simon. Thanks for your reply but this won't work for what I need to do. With Azure, a site can be running on multiple machines in the same environment. I need a unique path based on the machine, and I think the only way I can do this is by injecting a computed value into the web.config app settings - which I don't think can be done. The only other option I can think of is customising the Umbraco build, which is something I want to avoid.

    Unless I'm missing something. Is there a provider I can tap into, or a way I can set the path of the cache file programmatically?

  • Jon R. Humphrey 164 posts 455 karma points c-trib
    Jun 14, 2016 @ 09:50
    Jon R. Humphrey
    0

    Couldn't you hook into the application start event and pass in the setting then? I've done the same thing to append a reserved path, I'll see if I can find the code for you if you like?

  • Mitch 44 posts 159 karma points
    Jun 14, 2016 @ 11:44
    Mitch
    0

    Hi Jon

    Something like this is exactly what I need. I couldn't find how to do it though, so yes, if you have some code I'd love to see it.

  • Neil Tootell 73 posts 118 karma points
    Jun 14, 2016 @ 10:25
    Neil Tootell
    0

    Hi Mitch,

    On Umbraco 6.x there was a web.config setting called "umbracoContentXMLUseLocalTemp". If you set it to true, it saves the umbraco.config file into the webserver local temporary .net cache, not inside the web root.

    It should work on 7.x too, it would need testing.

    I'm not sure if this will work on Azure, but worth a try as it removes the need to specify the path for the cache file.

    Regards

    Neil

  • Mitch 44 posts 159 karma points
    Jun 14, 2016 @ 11:52
    Mitch
    0

    Hi Neil

    Thanks for your relpy. Yes I've seen this setting but not sure it will solve the issue we're having. Basically, we're having file locking issues where 2 or more Azure nodes, after auto scaling, try to access this file at the same time (this was reported to us by our DevOps guys so I don't have much more info).

    So we need a way to locate the umbraco.config file in a folder based on a variable like the machine name which will not be known at the time of deployment.

    I'm not an expert on Azure architecture but I will mention this solution to the DevOps and see what they say.

    Thanks

  • Neil Tootell 73 posts 118 karma points
    Jun 14, 2016 @ 13:51
    Neil Tootell
    0

    No worries Mitch.

    The trick is to remove the "working" files away from Azure's file system storage onto it's web worker process storage. Make sure you're on Umbraco 7.3+ as it has this all built in :)

    There's a couple of interesting posts on Umbraco and Azure...

    https://cultiv.nl/blog/making-sure-your-umbraco-site-performs-on-azure/

    https://www.degree53.com/blog/2015/october/highly-scalable-solutions-using-umbraco-and-azure

    Best of luck.

    n

  • Jon R. Humphrey 164 posts 455 karma points c-trib
    Jun 17, 2016 @ 18:58
    Jon R. Humphrey
    1

    Mitch,

    Deepest apologies! I've just finished up at Codegarden 16 so I wasn't checking things on here!

    Here's the code I used, just ignore the package actions parts unless you need them, but I'm sure you can see the parts you need!

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace My.PackageActions
    {
    using System.Configuration;
    using System.Xml;
    using Umbraco.Core.Configuration;
    using umbraco.cms.businesslogic.packager.standardPackageActions;
    using umbraco.interfaces;
    
    /// <summary>
    /// Adds a key to the web.config app settings
    /// </summary>
    /// <remarks>
    /// 
    /// Modified versions of 
    /// https://packageactioncontrib.codeplex.com/SourceControl/latest#PackageActionsContrib/AddAppConfigKey.cs
    /// and
    /// https://github.com/Merchello/src/Merchello.Web/PackageActions/AddAppConfigKey.cs
    /// 
    /// </remarks>
    
    public class UpdateUmbracoReservedPaths : IPackageAction
    {
    
        #region IPackageAction Members
    
        /// <summary>
        /// The key.
        /// </summary>
        private const string Key = "umbracoReservedPaths";
    
        /// <summary>
        /// The original value
        /// </summary>
        private static string _value = "~/umbraco,~/install/";
    
        /// <summary>
        /// The alias.
        /// </summary>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        public string Alias()
        {
        return "UpdateUmbracoReservedPaths";
        }
    
        /// <summary>
        /// The execute.
        /// </summary>
        /// <param name="packageName">
        /// The package name.
        /// </param>
        /// <param name="xmlData">
        /// The xml data.
        /// </param>
        /// <returns>
        /// True or false inicating success.
        /// </returns>
        public bool Execute(string packageName, XmlNode xmlData)
        {
        try
        {
            UpdateAppSettingsKey(Key, string.Join(",", _value, "~/Themes/"));
    
            return true;
        }
        catch
        {
            return false;
        }
        }
    
        /// <summary>
        /// The sample xml.
        /// </summary>
        /// <returns>
        /// The <see cref="XmlNode"/>.
        /// </returns>
        public XmlNode SampleXml()
        {
        const string Sample = "<Action runat=\"install\" undo=\"true/false\" alias=\"UpdateUmbracoReservedPaths\"></Action>";
    
        return helper.parseStringToXmlNode(Sample);
        }
    
        /// <summary>
        /// The undo.
        /// </summary>
        /// <param name="packageName">
        /// The package name.
        /// </param>
        /// <param name="xmlData">
        /// The xml data.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public bool Undo(string packageName, XmlNode xmlData)
        {
        try
        {
            ResetAppSettingsKey(Key, _value);
    
            return true;
        }
        catch
        {
            return false;
        }
        }
    
        #endregion
    
        #region helpers
    
        private static void UpdateAppSettingsKey(string key, string value)
        {
        var config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
        var appSettings = (AppSettingsSection)config.GetSection("appSettings");
    
        _value = appSettings.Settings[key].Value;
        appSettings.Settings.Remove(key);
        appSettings.Settings.Add(key, value);
    
        config.Save(ConfigurationSaveMode.Modified);
        }
    
        private static void ResetAppSettingsKey(string key, string value)
        {
        var config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
        var appSettings = (AppSettingsSection)config.GetSection("appSettings");
    
        appSettings.Settings.Remove(key);
        appSettings.Settings.Add(key, value);
    
        config.Save(ConfigurationSaveMode.Modified);
        }
        #endregion
    }
    }
    

    Let me know if there's any confusion and I'll see if I can answer them!

    Again, apologies for the delay,

    Jon

  • Mitch 44 posts 159 karma points
    Jun 21, 2016 @ 13:46
    Mitch
    1

    Many thanks for your replies guys. Jon, we don't think we can use the web.config editing solution as this will cause a website restart, but we'll look into it.

    Interesting links Neil, thanks. Not working on this now, but will let you know my findings.

  • Jon R. Humphrey 164 posts 455 karma points c-trib
    Jun 21, 2016 @ 14:35
    Jon R. Humphrey
    0

    Mitch,

    I completely understand the restart issue with the web.config but why not create your own config file somewhere and then read and write from that?

    That way you have a unique repo of the id's you're getting but you don't have to query the system each time or restart the app pool with the web.config route.

    Jon

Please Sign in or register to post replies

Write your reply to:

Draft