Copied to clipboard

Flag this post as spam?

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


  • John McKillip 33 posts 116 karma points
    Mar 26, 2015 @ 22:16
    John McKillip
    0

    Setting culture and hostname not allowing shared content: Umbraco Multi-Site instance.

    Hello,

    We are running into an issue with sharing content between two different websites in one instance of Umbraco.

    Before setting up the culture and hostnames, we were able to navigate to the shared Resources content and display it on the front-end. After setting the hostnames, all resources show a 404 when you try to navigate to them. The URL paths are correct, it just isn't finding the nodes. Wondering what the best solution is to allow shared content between multiple sites in one instance of Umbraco.

    I came across this Codegarden video while researching this topic: 

    http://stream.umbraco.org/video/9921509/40-different-high-traffic-sites-from-a

    About 25 min in, he talks about this exact thing and shows a really cool example. He doesn't give a lot of detail as to how he is doing it though. Our doc type structure is very similar to what he showed.

    Wondering if anyone else has had this issue and what they did to get around it. Our site is running Umbraco 7.2.4

    Any help on this would be greatly appreciated!

  • mike 90 posts 258 karma points
    Mar 27, 2015 @ 01:25
    mike
    0

    Do you mean you have it set like below?

    site 1: www.a.com
    site 2: www.b.com
    resources: www.a.com, www.b.com

    If you try assigning resources to just one domain does it start working?

  • John McKillip 33 posts 116 karma points
    Mar 27, 2015 @ 01:42
    John McKillip
    0

    I have different domains set for site 1 and site 2. Resources doesn't have any hostnames or cultures set (I just tried doing so and it didn't change anything). The only way I can get it to work correctly is if no hostnames are set for anything, but that is not an option.

  • John McKillip 33 posts 116 karma points
    Mar 27, 2015 @ 02:29
    John McKillip
    0

    Update:

    So, I got this working. It turns out that I have to set the hostname for the folders under Resources to both domains, so for instance, on the Publications folder, the hostnames look like this:

    www.site1.com/publications

    www.site2.com/publications

    Thanks Mike, your comment got me thinking on my way to the solution!

    Edit: So, I thought I would add this because the above didn't work exactly as I thought. When a request is made to any of the resources, regardless of which site you are on, the url always points to the first hostname listed. That being the case, I hade to change how we are getting the URL from the dynamic node. We were just using @node.Url. I had to change it to grab the local path of the url and append it like so:  <a href="~/@node.Parent.Name.ToLower()/@modUrl"> I realize this is a bit hacky, but it works. Wondering if there is a better way to do all of this?

  • Amir Khan 1282 posts 2739 karma points
    Jun 16, 2015 @ 20:45
    Amir Khan
    0

    Hi John,

    Where did you end up with this? It seems weird because adding /publications to the host names makes /publications appear twice in the url, were you experiencing this?

    Thanks, Amir

  • John McKillip 33 posts 116 karma points
    Jun 26, 2015 @ 16:43
    John McKillip
    0

    Hi Amir,

    We did not experience /publications appearing twice in the URL. The way we got it to work was to check the Absolute path of the media item and append it whenever it gets displayed:

    @foreach (var mediaItem in pagesToList.Skip((currentPage - 1) * itemsPerPage).Take(itemsPerPage))
        {
            Uri uri = new Uri(mediaItem.Url);
    
            <article>
                @if (mediaRoot)
                {
                    <span class="category">@mediaItem.Parent.Name</span>
                }
                <span class="date">
                    @String.Format("{0:MMMM d, yyyy}", mediaItem.date)
                    @if (mediaItem.HasValue("endDate"))
                    {
                        @String.Format("– {0:MMMM d, yyyy}", mediaItem.endDate)
                    }
                </span>
                <h2><a href="@uri.AbsolutePath">@mediaItem.Name</a></h2>
            </article>
        }
    

    Honestly, though, it is still kind of hacky. The hostnames don't work the way you would think in this type of situation. Wondering if it is a bug...

    Thanks! John

  • Tom 713 posts 954 karma points
    Oct 13, 2015 @ 02:36
    Tom
    0

    Hi John, We've had exactly the same experience with the 404s and the hostnames trying to replicate a virtually identical scenario..

    I'd love to know if this is a bug.. It seems like quite a bit of effort for something that you think should work without hostnames.. and some people seem to suggest it used to work without host names on the shared content.

    I wonder if someone from the core team could comment?

  • Christina Carter 12 posts 93 karma points
    Jan 14, 2016 @ 18:50
    Christina Carter
    0

    Hi Tom, John, others,

    Did you ever find a better way to do this? I'm trying to replicate the exact same scenario as well.

    In the meantime, if i follow John's example of adding both domains to the shared content, I want the shared content to live at the root of the sites. So, for example:

    Nodes:

    Blog 1

    Blog 2

    Shared Posts

    • sharedpostX
    • sharedpostY

    Urls:

    blog1.com/sharedpostX

    blog2.com/sharedpostX

    Thanks, C

  • Jules 269 posts 560 karma points
    Apr 23, 2016 @ 18:43
    Jules
    100

    The way this is usually done is this:

    1. Set up your website urls for Site 1 and Site 2 using culture and hostnames as the OP did.
    2. Create your Shared Content area as the OP did.

    Site1
        Publications
    Site2
        Publications
    Shared Content
        Publications Content

    1. However, you should understand that Shared Content and it's children are not part of the site - they are not children of either site node so to try and fix the url structure that Umbraco follows is going to require some hacking around - there is a much tidier way to do this. You should use a content picker on the Publications doc type that points to Publications content.

    Code on the template that renders Publications would need to find the PublicationsContent node. Something like the following (for brevity this misses out null checks)

    var sharedContent = Umbraco.TypedContentAtRoot().FirstOrDefault(x=>x.ContentType.Alias == "SharedContent");
    var pubContent = sharedContent.Children.FirstOrDefault(x=>x.ContentType.Alias == "PublicationsContent");
    

    Once you have the pubContent you can start building out your html

    <h1>@pubContent.GetPropertyValue<string>("mainHeading")</h1> 
    
    etc
    

    So you would have to add a SharedContent doctype and a template that renders the content of whatever node the Content Picker is pointed at. This way you don't have to muck around trying to get umbraco to do something that it won't naturally do.

  • John McKillip 33 posts 116 karma points
    Apr 25, 2016 @ 18:40
    John McKillip
    0

    Hi Jules,

    Awesome solution man. Cheers!

Please Sign in or register to post replies

Write your reply to:

Draft