Copied to clipboard

Flag this post as spam?

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


  • John Seto 37 posts 98 karma points
    Jun 29, 2016 @ 11:43
    John Seto
    0

    Multiple domain names on a single node same culture

    Hello all,

    I have a multilingual website. Each language is a root node. I'm using relations to link pages with the same content but different language.

    Each language root note has two domains with the same culture. One for the domain and one is localhost one (for development)

    eg.

    Home (French) ----- fr.xyz.ca (fr-ca) and fr.xyz.localhost (fr-ca)
    Home (English) ----- en.xyz.ca (en-ca) and en.xyz.localhost (fr-ca)
    

    when I look up the relation on the production server from French to the corresponding English node - the url always defaults to .localhost regardless of what order the localhost appears in the Culture.Hostname on the node.

    Any ideas how I can retrieve the list of domains under the corresponding node?

    I've tried AbsoluteUrl, Url of the IPublishedContent but all return localhost

    Cheers John

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Jun 29, 2016 @ 12:12
    Ismail Mayat
    1

    John,

    I had this recently and had to do some string manipulation this was for 4..11 site, you may need to tweak to fit your situation.

    /// <summary>
        /// a node can have more than one domain doing full url with domain
        /// via umbraco api will give you the first one it finds which may not be correct
        /// one, so get all the domains and compare with current request url and match
        /// </summary>
        /// <param name="url"></param>
        /// <param name="node"></param>
        /// <returns></returns>
        public static string GetFullUrlWhenMultiDomain(string url, IPublishedContent node)
        {
            string host = HttpContext.Current.Request.Url.Host;
    
            string protocol = HttpContext.Current.Request.Url.Scheme;
    
            if (host[2] == '.')
            {
    
                host = host.Substring(2);
            }
    
            var domains = Domain.GetDomainsById(node.Id);
    
            foreach (var domain in domains)
            {
                if (domain.Name.Contains(host))
                {
                    return protocol + "://" + domain.Name;
                }
            }
            return url;
        }
    

    Regards

    Ismail

  • John Seto 37 posts 98 karma points
    Jun 29, 2016 @ 15:42
    John Seto
    0

    Thanks Ismail for this. Do you know if there is an v7 equivalent to Domain.GetDomainsById(node.Id);
    as I gather it's deprecated

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Jun 29, 2016 @ 16:07
  • John Seto 37 posts 98 karma points
    Jun 29, 2016 @ 16:12
    John Seto
    0

    Thanks very much! For some reason when I searched I didn't see this thread.

    Your solution gets me closer than I have been before. Some of my domains I'm working with don't end in xyz.com some are xyz.fr, xyz.de etc. but thanks for your help.

    I'm closer to a solution.

Please Sign in or register to post replies

Write your reply to:

Draft