Try our conversational search powered by Generative AI!

Get StartPage from Multisite solution / Multi-tenant


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? :)



Aug 28, 2013 11:32

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:



Aug 28, 2013 11:50

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


Aug 28, 2013 11:58

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




     - SiteAPageA

     - SiteAPageB



     - SiteBPageA

          - SiteBPageB

          - SiteBPageC

     - SiteBPageD 


Sep 26, 2013 13:45

You may get current siteId by:



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


Edited, Sep 26, 2013 14:19

The problem Im stuck with is that:

       var id = EPiServer.Framework.Initialization.SiteMappingConfiguration.Instance.SiteId;

always returns But I can't understand why...


[ EPiServer.config ]

       <site siteId="">
              <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="" siteUrl="http://SiteA.extern.local" uiUrl="~/EPiServer/CMS/"
              utilUrl="~/util/" uiEditorCssPaths="~/Static/css/Editor.css"/>

       <site siteId="">
              <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="" pageFolderVirtualPathProvider="SitePageFiles"
              globalBlockFolderId="3" siteBlockFolderId="39" uiEditorCssPaths="~/Static/css/Editor.css"/>

       <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=""
              pageFolderVirtualPathProvider="SitePageFiles" globalBlockFolderId="3" siteBlockFolderId="162"/>

Sep 26, 2013 14:43

Can you post EPiServerFramework.config file fragments for site host mappings?

Sep 26, 2013 18:30

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)



Sep 26, 2013 22:27

Thank you guys for the help!, I ended up using Arild:s approach.

Sep 27, 2013 10:44

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 ?!

Sep 27, 2013 10:46

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

Sep 27, 2013 10:52
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.