This should give you a list of all startpages defined in your EPiServer site:
List<PageData> list = new List<PageData>();
foreach (SiteElement site in EPiServerCommonSection.Instance.Sites)
{
list.Add(DataFactory.Instance.GetPage(new PageReference(site.SiteSettings.PageStartId)));
}
However there is also a CurrentSite property that points to currently "active" site within given context:
EPiServerCommonSection.Instance.CurrentSite
Oh sorry, I didn't see that this was asked for v7. Here you go:
List<PageData> list = new List<PageData>();
var loader = ServiceLocator.Current.GetInstance<IContentRepository>();
foreach (SiteElement site in EPiServerSection.Instance.Sites)
{
list.Add(loader.Get<PageData>(new ContentReference(site.SiteSettings.PageStartId)));
}
Hi Valdis, thanks for your help but I'm afraid that your answer wasn't exactly what I wanted :)
Instead of giving me all sites startpages, I want current sites startpage.
For example, I am at "SiteBPageB", how do I get [SiteBStartPage]?
(PageReference.StartPage only gives me [SiteAStartPage] from all sites...)
[SiteAStartPage]
- SiteAPageA
- SiteAPageB
[SiteBStartPage]
- SiteBPageA
- SiteBPageB
- SiteBPageC
- SiteBPageD
You may get current siteId by:
EPiServer.Framework.Initialization.SiteMappingConfiguration.Instance.SiteId
And then:
var id = EPiServer.Framework.Initialization.SiteMappingConfiguration.Instance.SiteId;
var site = EPiServerSection.Instance.Sites.Cast<SiteElement>().First(s => s.SiteId.Equals(id));
var loader = ServiceLocator.Current.GetInstance<IContentRepository>();
var page = loader.Get<PageData>(new ContentReference(site.SiteSettings.PageStartId));
The problem Im stuck with is that:
var id = EPiServer.Framework.Initialization.SiteMappingConfiguration.Instance.SiteId;
always returns SiteA.se. But I can't understand why...
[ EPiServer.config ]
<sites>
<site siteId="SiteA.se">
<siteSettings httpCacheability="Public" httpCacheVaryByCustom="path" httpCacheVaryByParams="id,epslanguage" pageFolderVirtualPathProvider="SitePageFiles"
pageRootId="1" pageStartId="4" pageValidateTemplate="false" pageWastebasketId="2" globalBlockFolderId="3" siteBlockFolderId="3"
uiShowGlobalizationUserInterface="true" urlRebaseKind="ToRootRelative" siteDisplayName="SiteA.se" siteUrl="http://SiteA.extern.local" uiUrl="~/EPiServer/CMS/"
utilUrl="~/util/" uiEditorCssPaths="~/Static/css/Editor.css"/>
</site>
<site siteId="SiteB.se">
<siteSettings httpCacheVaryByCustom="path" httpCacheVaryByParams="id,epslanguage" httpCacheability="Public" urlRebaseKind="ToRootRelative"
uiShowGlobalizationUserInterface="true" pageRootId="1" pageStartId="38" pageWastebasketId="2" pageValidateTemplate="false"
siteUrl="http://SiteB.extern.local/" uiUrl="~/EPiServer/CMS/" utilUrl="~/util/" siteDisplayName="SiteB.se" pageFolderVirtualPathProvider="SitePageFiles"
globalBlockFolderId="3" siteBlockFolderId="39" uiEditorCssPaths="~/Static/css/Editor.css"/>
</site>
<site siteId="SiteC">
<siteSettings httpCacheVaryByCustom="path" httpCacheVaryByParams="id,epslanguage" httpCacheability="Public" uiEditorCssPaths="~/Static/css/Editor.css"
urlRebaseKind="ToRootRelative" uiShowGlobalizationUserInterface="true" pageRootId="1" pageStartId="161" pageWastebasketId="2" pageValidateTemplate="false"
siteUrl="http://SiteC.extern.local/" uiUrl="~/EPiServer/CMS/" utilUrl="~/util/" siteDisplayName="SiteC.se"
pageFolderVirtualPathProvider="SitePageFiles" globalBlockFolderId="3" siteBlockFolderId="162"/>
</site>
</sites>
Can you post EPiServerFramework.config file fragments for site host mappings?
There's probably a sexier way of doing it in EPi7, but in EPi6 you could easily traverse upwards by recursively calling CurrentPage.ParentLink and check each time if CurrentPage is your SiteBStartPage pagetype. (Alternatively there's the DataFactory.GetAncestors(PageReference pageref) call.) A bit dirty but would do the trick (and isn't terribly memory expensive if I remember correctly)
Yup, sounds like this could a fallback solution. Anyway - just curious, are you running each site in it's own app pool? I just created a sandbox env for multiple sites - and really seems like SiteId is always returning first one. Sounds like a bug ?!
No, I use 1 Appool for each site.
Exactly what I felt, some kind of strange bug. Then I thougt that maybe there was some kind of
simillar function as PageReference.StartPage, but for multisites, but no :)
Hi everyone,
I need to get the StartPage from a multisite-solution in EPiServer.
I've tried "PageReference.StartPage" but it only gives me the first StartPage it can find in the tree-view.
I would rather get the startpage from current (active) site, any ideas? :)