U4-1323 - Inconsistent media folder location handling

Created by Hardy Wang 14 Dec 2012, 14:01:06 Updated by Sebastiaan Janssen 26 Dec 2012, 11:15:01

Starting from 4.9.0 (or maybe 4.8.0) the way to move media folder to another location is done via FileSystemProviders instead of . It works fine for media library, but inside Umbraco code (I debugged source code of 4.11.1, and I believe all previous versions have same bug) there is an inconsistency.

In Umbraco.Core.IO.SystemDirectories class, the Media property has the code of public static string Media { get { return IOHelper.ReturnPath("umbracoMediaPath", "~/media"); } }

It uses IOHelper.ReturnPath function, and in this function (in Umbraco.Core.IO.IOHelper class) the source code is

    internal static string ReturnPath(string settingsKey, string standardPath, bool useTilde)
        string retval = ConfigurationManager.AppSettings[settingsKey];

        if (string.IsNullOrEmpty(retval))
            retval = standardPath;

        return retval.TrimEnd('/');

And it is very obviously that the code is looking for an app config entry "umbracoMediaPath" to get what is the folder of media.

The direct impact of such bug is, I have configured FileSystemProviders.config in following way

When I upload images to media library, all the images appear under http://my-server/MyRoot/media/1234/some.jpg which is correct. And in content editor I can insert images to RTE from media library. Before I click "Save" or "Publish" button the path is still correct, but after posted to server, the code eventually calls to tinyMCE.cs class, there is a step in it to clean up tag, which eventually will use that incorrect path to normalize tag and eventually /MyRoot/ is stripped from the URL.

I can have a temporary work-around to add the entry back to web.config, but it is redundant to me. If Umbraco team decided to use FileSystemProviders and central point to config folder path, then it should be the only place to use.

P.S During my debug of editContent.aspx.cs I noticed you have On_Init, Page_Load, Save, Publish functions/event handlers and so on, before Save is even executed, after Page_Load finished running, the code will run all whole bunch of event handlers in base class or controller's own handlers, the actual saving to database happens there (before Save function). Doesn't such implementation cause confusion? By naming of the function Save should be the one to take care of actually saving, but in fact it does not.


Sebastiaan Janssen 26 Dec 2012, 07:33:46

Fixed in changeset 557323fb1ee0 Feel free to update to the nightly 4.11.2 (build 8 contains this fix) if you want to get rid of the extra configuration key in you web.config file.

Priority: Normal

Type: Bug

State: Fixed


Difficulty: Normal

Category: Editor

Backwards Compatible: True

Fix Submitted:

Affected versions: 4.9.0, 4.10.0, 4.11.0, 4.9.1, 4.11.1

Due in version: 4.11.2


Story Points: