Retrieving full page URL in multi-site scenario
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.
Really no clue? Anyone?
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
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
Hi Marek, that what i did for my multisite
var multisiteContext = SystemManager.CurrentContext;
var currentSite = multisiteContext.CurrentSite;
var url = domain + pageNode.GetUrl(culture).Trim(
'~'
);
This should work for you
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).
You can try to receive specific site and take liveUrl from site
var targetPageMultisite = MultisiteManager.GetManager().GetSites().First(s=>s.SiteMapRootNodeId == page.NavigationNode.RootNodeId);
It should allows you to receive all multisite urls
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.
May be targetPageMultisite is incorrect.
This method MultisiteManager.GetManager().GetSites() working fine for me. All sites have correct LiveUrl property.