Copied to clipboard

Flag this post as spam?

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


  • Paul de Quant 340 posts 1329 karma points
    Aug 16, 2017 @ 14:59
    Paul de Quant
    0

    Getting domain values from Cultures and Hostnames

    Hello,

    Can anyone tell me if it's possible to view the list of domains added via the 'Culture and Hostnames' in C# preferably strongly typed.

    I need to loop through all top root level pages and do a domain check.

    Thanks

    Paul

  • Nicholas Westby 1893 posts 6332 karma points c-trib
    Aug 16, 2017 @ 15:10
    Nicholas Westby
    101

    Here's a snippet of code I have that does similar:

    var contentCache = context.ContentCache;
    var services = ApplicationContext.Current.Services;
    var domainService = services.DomainService;
    
    // Get homepages.
    return domainService
        // First, get each content node with a domain set.
        .GetAll(true)
        .Select(x => new
        {
            x.DomainName,
            x.RootContentId,
            Node = contentCache.GetById(x.RootContentId.Value)
        })
        // Avoid null exceptions.
        .Where(x => x.Node != null);
    

    I'm sure you can figure out the rest from that.

  • Paul de Quant 340 posts 1329 karma points
    Aug 16, 2017 @ 15:22
    Paul de Quant
    0

    Legend.

    Thanks Nicholas :-)

  • Mangirish Wagle 34 posts 106 karma points
    Mar 12, 2019 @ 14:15
    Mangirish Wagle
    0

    Hello Nicholas,

    var contentCache = context.ContentCache;
    

    throws an error. Secondly, in which type of file to implement this. Is it .cshtml or .cs?

  • Nicholas Westby 1893 posts 6332 karma points c-trib
    Mar 12, 2019 @ 15:26
    Nicholas Westby
    0

    Hi Mangirish,

    This thread has already been answered. Please ask that question in a new thread. Be sure to mention details (e.g., where you tried to use that line, what error you got, if it was a compile or runtime error, a screenshot, and so on).

Please Sign in or register to post replies

Write your reply to:

Draft