Copied to clipboard

Flag this post as spam?

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


  • Richard Thompson 100 posts 336 karma points
    Oct 12, 2015 @ 14:35
    Richard Thompson
    0

    FileSecurityException file outside root in console app

    Hi,

    I'm trying to access an Umbraco 7.3 site from a console application. I've copied the example at https://github.com/sitereactor/umbraco-console-example/tree/master/UmbConsole.

    When calling GetContentOfContentType I receive a FileSecurityException telling me a view file is outside this filesystem's root.

    Does anybody know how I can solve this

  • David Veksler 81 posts 166 karma points
    Oct 28, 2015 @ 12:53
    David Veksler
    1

    I can confirm that this issue is due to the 7.3 upgrade. Worked fine in 7.2.6.

    FYI http://issues.umbraco.org/issue/U4-6865

  • Richard Thompson 100 posts 336 karma points
    Oct 28, 2015 @ 12:56
    Richard Thompson
    0

    Thanks for letting me know, I'll take a look at this.

  • Jasper van der Sterren 13 posts 33 karma points
    Nov 19, 2015 @ 10:21
    Jasper van der Sterren
    0

    Hi Richard,

    I encounter the same problem. Have you found a fix for this? As far as I can see at the moment, it can only be fixed by a core change and custom source compile.

    Regards, Jasper.

  • Richard Thompson 100 posts 336 karma points
    Nov 19, 2015 @ 10:40
    Richard Thompson
    0

    Hi,

    I haven't found a solution. I ended up using some console app code from an Umbraco 6 site, updated the Umbraco dependencies and copied in some parts of the web.config and that has done the job for me.

  • Jasper van der Sterren 13 posts 33 karma points
    Nov 19, 2015 @ 12:12
    Jasper van der Sterren
    0

    Didn't you run into problems because of the different database schema? I upgraded my site to 7.3.1, and left the console app running on 7.2.8, but even then I get errors because of the db schema.

  • Richard Thompson 100 posts 336 karma points
    Nov 19, 2015 @ 12:22
    Richard Thompson
    0

    I didn't but I guess it was because I'm using the same version for the app and the website.

  • Ron G 41 posts 137 karma points
    Dec 04, 2015 @ 08:17
    Ron G
    0

    Richard,

    I'm also having issues trying to connect to Umbraco from a console app. Can you point to us where you found the console app code from an Umbraco 6 site? Or can you post your working code here?

    Thanks!

  • Richard Thompson 100 posts 336 karma points
    Dec 04, 2015 @ 09:22
  • Andy Blyth 9 posts 120 karma points
    Dec 04, 2015 @ 10:52
    Andy Blyth
    0

    Hope someone comes up with a solution for this. I'll keep tinkering with it, see if I can come up with a solution.

  • Ron G 41 posts 137 karma points
    Dec 04, 2015 @ 15:26
    Ron G
    0

    I tried updating the Umbraco dependencies (to 7.3.1) in the Umbraco-Console-Example but when I try to perform the 'list' command, I'm getting the original error:

    ERROR: An unhandled exception of type 'Umbraco.Core.IO.FileSecurityException' occurred in Umbraco.Core.dll File 'Home.cshtml' is outside this filesystem's root.

    var rootContent = contentService.GetRootContent(); // ERROR HERE ***
    

    Full method:

    private static void ListContentNodes(IContentService contentService)
        {
            //Get the Root Content
            var rootContent = contentService.GetRootContent(); <== ERROR HERE **********
            foreach (var content in rootContent)
            {
                Console.WriteLine("Root Content: " + content.Name + ", Id: " + content.Id);
                //Get Descendants of the current content and write it to the console ordered by level
                var descendants = contentService.GetDescendants(content);
                foreach (var descendant in descendants.OrderBy(x => x.Level))
                {
                    Console.WriteLine("Name: " + descendant.Name + ", Id: " + descendant.Id + " - Parent Id: " + descendant.ParentId);
                }
            }
        }
    

    Anyone know of a fix for this?

  • Ron G 41 posts 137 karma points
    Dec 04, 2015 @ 18:58
    Ron G
    0

    It appears the issue is with: GetRootContent()

    If I run:

    Umbraco.Core.Models.IContent content = contentService.GetById(1000);
    

    ... It works fine.

    Its something with GetRootContent() which seems looks for the template on the filesystem as well. Not sure why.

  • Adam Prendergast 33 posts 77 karma points MVP c-trib
    Dec 07, 2015 @ 20:19
    Adam Prendergast
    0

    I'm having the same problem after upgrading to version from 7.2.8 to 7.3.

    The exception I am getting is:

    File 'UmbracoPage.cshtml' is outside this filesystem's root.
    

    This is obviously a problem with using the (until now) excellent UmbConsole example:

    https://github.com/sitereactor/umbraco-console-example/tree/master/UmbConsole

    Does anyone have a vague clue to where the error is coming from?

    I've tried to be clever and create an 'UmbracoPage.cshtml' file at the root... but no joy.

  • Onno Sloof 23 posts 43 karma points
    Dec 15, 2015 @ 14:09
    Onno Sloof
    0

    Hi,

    does anyone have a solution for this problem?

    I also have the same issue. contentService.GetById(1000); is working when running from Visual Studio, but gives error of file outside this filesystem's root when running the executable outside Visual Studio

    I'm also using the UmbConsole example app.

  • Raimond 6 posts 116 karma points
    Jan 25, 2016 @ 08:50
    Raimond
    0

    While trying to import a bunch of content items, I also ran into this issue with 7.4.0-beta2.

    After having tried the solutions outlined in http://issues.umbraco.org/issue/U4-6865, which did not work for me, I simply changed the following in UmbConsole's ConsoleApplicationBase.cs, line 18:

    var binDirectory = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory);
    

    Set this to a root directory of a valid Umbraco website:

    var binDirectory = new DirectoryInfo("D:\\Development\\MyUmbracoWebsite");
    

    After making the change, I was able to fetch and create content.

  • Alastair Todd 44 posts 142 karma points
    Feb 05, 2016 @ 18:50
    Alastair Todd
    0

    This is happening to me since moving to 7.3.7.

    Changing the bin directory just creates a load of new missing dll issues.

    https://github.com/sitereactor/umbraco-console-example/tree/master/UmbConsole

    is now broken and im sat here wondering how the hell im going to migrate my content in a sensible controlled (me) way and without paying for it.

  • Comment author was deleted

    Mar 22, 2016 @ 15:10

    So did anyone manage to get this workin on umb > 7.3 ? Facing the same issue...

  • benjamin 1 post 73 karma points
    Mar 29, 2016 @ 15:16
    benjamin
    2

    Any solution behind this? I've tried to get some sort of physical context up, but there seems to be an unending dependency chain for the custom repository factory.

    We are using 7.3.1 in a console app that grabs the umbraco data, but it seems like the system now checks for the views, which, don't exist. I was wondering if anyone else has found something that works as a get around without building the part of the source code of umbraco that it is requesting. the "Umbraco.Core.IO.PhysicalFileSystem.FIleExists" check.

    The only methods that we are trying right now are either mocking the content before hand(which could be really unnecessary), or intercepting the call and returning it true always.

    we're not sure yet if we can have parts of the solution be different versions of umbraco at the same time. For example having this console umbraco data grab app be version 7.2.1 and the umbraco website be 7.3.1.

    More testing.

    ideas?


    after awhile i found this worked as a solution both in dev and publish. I revisited Raimonds idea and found the oddest thing. removing the slash in the domain call made it so umbraco didn't complain anymore. :-) so, from this:

    var binDirectory = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory);
    

    to this:

    string regularPath = AppDomain.CurrentDomain.BaseDirectory;
                string newPath = regularPath.Remove(regularPath.Length - 1);
                var binDirectory = new DirectoryInfo(newPath);
    
  • Marcin Zajkowski 112 posts 585 karma points MVP 7x c-trib
    Apr 04, 2016 @ 14:37
    Marcin Zajkowski
    0

    Steps which helped me to fire up console app with latest v7.4.2 build:

    1. Removed / renamed App_Start folder for the time of usage my console app (in my case Ninject startups and other startup code which can't be fired without mocks).
    2. Try & catch exceptions during custom providers mapping to UrlProviderResolver.Current (is not accessible during startup in console).
    3. Hacked Umbraco.Core (thanks to @AnthonyDotNet) and performed custom build of used version (v7.4.2 in my case) with replaced line "throw new FileSecurityException("File '" + opath + "' is outside this filesystem's root.");" in Umbraco-CMS\src\Umbraco.Core\IO\PhysicalFileSystem.cs to "return fpath;".
    4. Backed-up / moved DLLs causing errors. In my case: Our.Umbraco.PropertyEditorConverters.dll which caused some erorrs with virtual paths.

    After those steps console app created context and is working fine now.

  • Comment author was deleted

    Apr 04, 2016 @ 14:39

    FYI There is also this version that runs if you place it in your site root https://github.com/lars-erik/umbraco-console-example

  • Marcin Zajkowski 112 posts 585 karma points MVP 7x c-trib
    Apr 04, 2016 @ 15:03
    Marcin Zajkowski
    0

    Wow, it's just working. Thanks Tim!

  • Ben Sapp 2 posts 72 karma points
    Aug 20, 2017 @ 08:00
    Ben Sapp
    0

    This is pure gold.

  • Luis Paulo Silva 2 posts 74 karma points
    Aug 17, 2017 @ 12:32
    Luis Paulo Silva
    1

    Hi all,

    Sorry for necroing this 1 year old post

    I've made the required changes on Umbraco 7.5.7 so it can work with Console applications.

    I've made a fork and a fixed release branch for this particular problem.

    The problem I found was that the _rootPath was malformed and caused the directory not to be found, even if you placed the cshtml mocked file in the right folder it would always blow up because of that.

    I hope this helps you all.

    https://github.com/Mindbus/Umbraco-CMS/tree/release-7.5.7-GetRootContentFix

  • Tom 713 posts 954 karma points
    Oct 03, 2017 @ 06:23
    Tom
    0

    I created a console app in a separate project using the getbootmanager fix:

    // This is a workaround for FileSecurityException (refer https://our.umbraco.org/forum/umbraco-7/using-umbraco-7/72095-filesecurityexception-file-outside-root-in-console-app)
            string regularPath = AppDomain.CurrentDomain.BaseDirectory;
            string newPath = regularPath.Remove(regularPath.Length - 1);
            var binDirectory = new DirectoryInfo(newPath);
    

    But then was seeing the file security exception error when trying to point back to the web project's root folder..

    I then tried tim's app in the web root directory but it is unable to resolve an azure file system provider.

    Can anyone confirm that for v7 I should be running the exe from the web project's root folder or should it be in the bin with then the boot manager base path modified etc?

  • Kevin 2 posts 72 karma points
    Jan 09, 2018 @ 16:36
    Kevin
    0

    My problem was that the BaseDirectory the ResolveBasePath method returned was not the same the first time I ran and on subsequent runs. This is because GetBootManager copies over the config folder to the binDirectory and so on successive runs the BaseDirectory was the same as the binDirectory.

    //Copy config files to AppDomain's base directory
    if (binDirectory.FullName.Equals(BaseDirectory) == false &&
        appDomainConfigPath.Exists == false)
    {
        appDomainConfigPath.Create();
        var baseConfigPath = new DirectoryInfo(Path.Combine(BaseDirectory, "config"));
        var sourceFiles = baseConfigPath.GetFiles("*.config", SearchOption.TopDirectoryOnly);
        foreach (var sourceFile in sourceFiles)
        {
            sourceFile.CopyTo(sourceFile.FullName.Replace(baseConfigPath.FullName, appDomainConfigPath.FullName), true);
        }
    }
    

    It looks like this might have been by design, but it didn't work for me so I simply changed

    BaseDirectory = ResolveBasePath(binDirectory);
    

    to

    BaseDirectory = ResolveBasePath(binDirectory.Parent);
    
Please Sign in or register to post replies

Write your reply to:

Draft