Copied to clipboard

Flag this post as spam?

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


  • James Pawsey 10 posts 119 karma points c-trib
    Mar 10, 2017 @ 17:32
    James Pawsey
    0

    'GlobalSettings' does not contain a definition for 'UmbracoMvcArea'

    Hi,

    I am trying to use an MVC controller for my package and I am following the documentation using GlobalSettings.UmbracoMvcArea but I get the error in the subject.

    I have added all of the using statements that Visual Studio was asking for. The code in the example is:

    url: GlobalSettings.UmbracoMvcArea + "/backoffice/cats/{action}/{id}"
    
  • Marc Goodson 2133 posts 14273 karma points MVP 8x c-trib
    Mar 10, 2017 @ 21:47
    Marc Goodson
    100

    Hi James

    The documentation is out of date :-(

    GlobalSettings is marked as internal in the core and so you cannot access the UmbracoMvcArea property to add your custom route.

    Also when you have right clicked and resolved your GlobalSettings class, it has found an older GlobalSetting class that is public from the older (lowercase u) umbraco namespace, and this does not contain the UmbracoMvcArea property which is why you are getting the specific error message.

    If you read the umbracoPath property from the web.config this should I think give the correct location of the /umbraco folder to map your custom mvc route in the backoffice:

    protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext
    applicationContext)
            {
                var umbracoPath = System.Configuration.ConfigurationManager.AppSettings["umbracoPath"];
                if (umbracoPath.StartsWith(SystemDirectories.Root)) // beware of TrimStart, see U4-2518
                    umbracoPath = umbracoPath.Substring(SystemDirectories.Root.Length);
                umbracoPath = umbracoPath.TrimStart('~').TrimStart('/').Replace('/', '-').Trim().ToLower();
    
                RouteTable.Routes.MapRoute(
                name: "cats",
                url: umbracoPath + "/backoffice/cats/{action}/{id}",
                defaults: new
                {
                    controller = "Cats",
                    action = "Meow",
                    id = UrlParameter.Optional
                });
            }
    

    Note it needs to have it's ~ and leading / removed...

    When working with data in the backoffice, I tend to use an UmbracoAuthorizedJsonController or UmbracoAuthorizedApiController (as these are routed by convention) to expose data via Web Api endpoints, that I then consume in AngularJs, rather than creating an actual MVC controller for the backoffice, but I'm not sure what you are up to!! but the above should enable you to map the route correctly!

    regards

    Marc

  • James Pawsey 10 posts 119 karma points c-trib
    Mar 13, 2017 @ 09:05
    James Pawsey
    0

    Hi Marc,

    Thanks for the reply, I will give it a go today.

  • Marc Goodson 2133 posts 14273 karma points MVP 8x c-trib
    Mar 13, 2017 @ 18:43
    Marc Goodson
    0

    Hi James

    If that's all good, I'll put in a pull request to update the documentation!

    regards

    Marc

  • James Pawsey 10 posts 119 karma points c-trib
    Mar 14, 2017 @ 09:03
    James Pawsey
    0

    Hi Marc,

    That did work thanks!

Please Sign in or register to post replies

Write your reply to:

Draft