+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Retrieving full page URL in multi-site scenario

Retrieving full page URL in multi-site scenario

9 posts, 0 answered
  1. Marek
    Marek avatar
    5 posts
    Registered:
    22 Dec 2011
    31 May
    Link to this post

    Hi,

    I'm developing a web service (WCF) inside SF (9.1) which should return some of the page data, most importantly in this case - actual front-end page URL. I have couple of multi-sites, like example.com (default), example.com/msite1, example.com/msite2 etc.

    I've tried to apply the solution described in documentation (http://docs.sitefinity.com/for-developers-retrieve-page-url):

    var pageNode = page.NavigationNode;
    var siteMap = SiteMapBase.GetCurrentProvider();
    var siteMapNode = siteMap.FindSiteMapNodeFromKey(pageNode.Id.ToString()) as PageSiteNode;
     
    if (siteMapNode == null)
    {
        return string.Empty;
    }
     
    var url = siteMapNode.GetUrl(CultureInfo.CurrentCulture, true);
     
    return UrlPath.ResolveUrl(url, true, true);

    but it returns the url of the default multi-site, that is: http://example.com/page-url instead of http://example.com/msite1/page-url

    Since most of the operations related with multi-sites and sites in API are performed in static context (!) I also tried to statically switching to the target multi-site context:

    var multisiteContext = SystemManager.CurrentContext as MultisiteContext;
    if (multisiteContext == null)
    {
        return null;
    }
    var currentMultisite = multisiteContext.CurrentSite;
    var targetPageMultisite = multisiteContext.GetSiteBySiteMapRoot(page.NavigationNode.RootNodeId);
     
    multisiteContext.ChangeCurrentSite(targetPageMultisite);
     
    var result = new ...
    {
        ...
        DisplayUrl = UrlPath.ResolveAbsoluteUrl(page.NavigationNode.GetFullUrl(), true),
        ...
    };
     
    multisiteContext.ChangeCurrentSite(currentMultisite);
     
    return result;

    but with exactly the same result as above.

    This operation is so basic that I cannot imagine how it was made so complex in SiteFinity SDK...

    Please advice how can I retrieve the proper absolute URL of specific page including its multi-site context.

  2. Marek
    Marek avatar
    5 posts
    Registered:
    22 Dec 2011
    03 Jun
    Link to this post
    Really no clue? Anyone?
  3. Svetoslav Manchev
    Svetoslav Manchev avatar
    735 posts
    Registered:
    29 Nov 2016
    03 Jun
    Link to this post
    Hi Marek,

    The following KB article, could be useful:
    http://www.sitefinity.com/developer-network/knowledge-base/details/how-to-get-all-the-pages-from-a-specific-site-in-a-multisite-project

    Regards,
    Svetoslav Manchev
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  4. Marek
    Marek avatar
    5 posts
    Registered:
    22 Dec 2011
    03 Jun
    Link to this post

    Unfortunately it's not.

    Please, read topic and content of the question carefully - I'm having problem with resolving page URL, not with retrieving the pages and their data

  5. Victor Leontyev
    Victor Leontyev avatar
    65 posts
    Registered:
    01 Jul 2014
    09 Jun
    Link to this post

    Hi Marek, that what i did for my multisite

    var multisiteContext = SystemManager.CurrentContext;
    var currentSite = multisiteContext.CurrentSite;
    var domain = (currentSite.RequiresSsl ? "https://" : "http://") + currentSite.LiveUrl;
    var url = domain + pageNode.GetUrl(culture).Trim('~');

    This should work for you

  6. Marek
    Marek avatar
    5 posts
    Registered:
    22 Dec 2011
    09 Jun in reply to Victor Leontyev
    Link to this post

    Your solution works well when you run it in the context (URL) of the proper multi-site, but it does not work in my case.

    Please note that multisiteContext.CurrentSite works in a static context so it simply cannot return the proper multi-site URL when you run the code from a default multi-site only (as in this case).

  7. Victor Leontyev
    Victor Leontyev avatar
    65 posts
    Registered:
    01 Jul 2014
    09 Jun
    Link to this post

    You can try to receive specific site and take liveUrl from site

    var targetPageMultisite = MultisiteManager.GetManager().GetSites().First(s=>s.SiteMapRootNodeId == page.NavigationNode.RootNodeId);
    var domain = (targetPageMultisite.RequiresSsl ? "https://" : "http://") + targetPageMultisite.LiveUrl;

    It should allows you to receive all multisite urls

  8. Marek
    Marek avatar
    5 posts
    Registered:
    22 Dec 2011
    14 Jun
    Link to this post

    Thank you for the hint but this doesn't work either (tested). The 'targetPageMultisite.LiveUrl' property does not resolve properly to multisite url.

    I don't know if it's relevant, but in my case all the multisites are in single domain but on different paths:
    * Default multisite: http://example.com/
    * Multisite A: http://example.com/a/
    * Multisite B: http://example.com/b/
    etc.

    The 'targetPageMultisite.LiveUrl' always resolves to the default multisite URL.

  9. Victor Leontyev
    Victor Leontyev avatar
    65 posts
    Registered:
    01 Jul 2014
    14 Jun in reply to Marek
    Link to this post

    May be targetPageMultisite is incorrect.

    This method MultisiteManager.GetManager().GetSites() working fine for me. All sites have correct LiveUrl property.

     

9 posts, 0 answered