Copied to clipboard

Flag this post as spam?

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


  • PRK 47 posts 119 karma points
    Feb 11, 2014 @ 09:51
    PRK
    0

    Alternative to Domain.GetRootFromDomain() ?

    Hi,

    does anybody know an alternative to Domain.GetRootFromDomain() ?

  • Alex Skrypnyk 6182 posts 24283 karma points MVP 8x admin c-trib
    Feb 11, 2014 @ 10:00
    Alex Skrypnyk
    0

    Hi PRK,

    You can use one of this methods to get root nodes:

    CurrentPage.AncestorOrSelf(1) or UmbracoContext.Application.Services.ContentService.GetRootContent()

    Thanks, Alex

  • Sebastiaan Janssen 5061 posts 15544 karma points MVP admin hq
    Feb 11, 2014 @ 10:02
    Sebastiaan Janssen
    0

    What's wrong with Domain.GetRootFromDomain()?

  • PRK 47 posts 119 karma points
    Feb 11, 2014 @ 10:19
    PRK
    0

    Hi all,

    thanks for your answers.

    @Sebastian:

    Nothing wrong with Domain.GetRootFromDomain(). But I can`t find it in Umbraco V7.

    @Alex:

    Thanks, I haven not seen that (UmbracoContext.Application.Services.ContentService.GetRootContent()).

     

  • PRK 47 posts 119 karma points
    Feb 11, 2014 @ 10:29
    PRK
    0

    Okay,

    UmbracoContext.Application.Services.ContentService.GetRootContent() is not the right answer.

    I want a error404 redirect on requested Servername.

     

    Heres my Code:

     

    public bool Execute(string url)
     {
                var server = HttpContext.Current.Request.ServerVariables["SERVER_NAME"].ToLower();
         
                //Doesn`t work in V7
                var rootNodeId = Domain.GetRootFromDomain(server);

                if (rootNodeId == -1) return false;

                // redirect to error404 page
                var errorPage = ConfigurationService.Instance.GetError404(rootNodeId).Url;
                HttpContext.Current.Response.Redirect(errorPage, true);

                return true;
    }

     

     

     

  • Sebastiaan Janssen 5061 posts 15544 karma points MVP admin hq
    Feb 11, 2014 @ 10:37
    Sebastiaan Janssen
    100

    This works perfectly in 7.0.3?

            @{
                string currentDomain = HttpContext.Current.Request.ServerVariables["SERVER_NAME"];
                int rootNodeID = umbraco.cms.businesslogic.web.Domain.GetRootFromDomain(currentDomain);
            }
            <h2>@currentDomain (@rootNodeID )</h2>
    

    Maybe you're just missing the namespace.

  • PRK 47 posts 119 karma points
    Feb 11, 2014 @ 11:30
    PRK
    0

    I don`t know why, but I have to reference umbraco.cms several times in vs20130 before it worked.

    Rookie error  :-)

  • Chris Van Oort 110 posts 371 karma points
    Jan 25, 2017 @ 17:25
    Chris Van Oort
    0

    Sorry to bump a really old topic, but I'm running into this same problem where "Domain" from "umbraco.cms.businesslogic" has been marked obsolete and I need to fix it in Umbraco 7.5.8.

    Has anyone solved this?

    The error notes this, but I'm not sure how I can use either one of these interfaces to access the same method.

    'Domain' is obsolete: 'Use Umbraco.Core.Models.IDomain and Umbraco.Core.Services.IDomainService instead'
    
  • Sebastiaan Janssen 5061 posts 15544 karma points MVP admin hq
    Jan 25, 2017 @ 17:57
    Sebastiaan Janssen
    3

    Did you know that open source is awesome? ;-)))

    Here's what I see when I look at the source of the method you shouldn't use any more:

        public static int GetRootFromDomain(string DomainName)
        {
            var found = ApplicationContext.Current.Services.DomainService.GetByName(DomainName);
            return found == null ? -1 : found.RootContentId ?? -1;
        }
    
  • Chris Van Oort 110 posts 371 karma points
    Jan 25, 2017 @ 17:59
    Chris Van Oort
    0

    That's killer; thank you! I hadn't thought to look at the source code.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies