Retrieving full page URL in multi-site scenario

Posted by Community Admin on 04-Aug-2018 13:29

Retrieving full page URL in multi-site scenario

All Replies

Posted by Community Admin on 31-May-2016 00:00

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 (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 example.com/.../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.

Posted by Community Admin on 03-Jun-2016 00:00

Really no clue? Anyone?

Posted by Community Admin on 03-Jun-2016 00:00

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
 

Posted by Community Admin on 03-Jun-2016 00:00

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

Posted by Community Admin on 09-Jun-2016 00:00

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

Posted by Community Admin on 09-Jun-2016 00:00

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).

Posted by Community Admin on 09-Jun-2016 00:00

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

Posted by Community Admin on 14-Jun-2016 00:00

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.

Posted by Community Admin on 14-Jun-2016 00:00

May be targetPageMultisite is incorrect.

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

 

This thread is closed