Get StartPage from Multisite solution / Multi-tenant

Vote:
 

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

 

 

#74462
Aug 28, 2013 11:32
Vote:
 

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

    

#74463
Aug 28, 2013 11:50
Vote:
 

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

    

#74465
Aug 28, 2013 11:58
Vote:
 

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 

 

#75471
Sep 26, 2013 13:45
Vote:
 

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

    

#75472
Edited, Sep 26, 2013 14:19
Vote:
 

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>

#75473
Sep 26, 2013 14:43
Vote:
 

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

#75486
Sep 26, 2013 18:30
Vote:
 

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)

 

 

#75489
Sep 26, 2013 22:27
Vote:
 

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

#75513
Sep 27, 2013 10:44
Vote:
 

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

#75514
Sep 27, 2013 10:46
Vote:
 

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

#75515
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.