Mari Jørgensen
Sep 27, 2010
  4829
(3 votes)

Did you know of the GetSettingsFromPage() method?

Info-ShieldFinding the start page in an EPiServer solution is usually easy as pie – it is accessible using a static property on the PageReference class.

But if you have several sites sharing database in an Enterprise solution, and you are trying to get hold of the start page from inside a scheduled task, you will soon notice that it’s a bit more tricky.

When the scheduled task is executed you will have no control over which of the sites the PageReference.StartPage will point to.
(In my tests, PageReference.StartPage seem to run in the context of the first site configured in the site section in episerver.config).

This is where the GetSettingsFromPage method becomes handy – if you have a reference to a page on your site, you can find the site settings for that page. When you have the settings, it’s pretty straight forward to find the start page:

   1: Settings settingsFromPage = 
   2:       DataFactory.Instance.GetSettingsFromPage(page.PageLink);
   3: PageReference myStartPage = 
   4:       new PageReference(settingsFromPage.PageStartId);

The ironic part is that I found the solution while searching and finding an old blog post written by myself… (!).

Sep 27, 2010

Comments

Sep 27, 2010 01:46 PM

Thank you for sharing this. Previously I've used my own function which recursively searches for the start page and then uses the Id of the found page to get the right settings.

Sep 27, 2010 07:40 PM

Nice. :)

Joel Abrahamsson
Joel Abrahamsson Sep 28, 2010 08:28 AM

Interesting! Thanks for sharing this.

Sep 29, 2010 12:58 AM

Very nice .I am developing an enterprise sites and was thinking i will have to write some custom code to achieve this .

Please login to comment.
Latest blogs
Opti ID overview

Opti ID allows you to log in once and switch between Optimizely products using Okta, Entra ID, or a local account. You can also manage all your use...

K Khan | Jul 26, 2024

Getting Started with Optimizely SaaS using Next.js Starter App - Extend a component - Part 3

This is the final part of our Optimizely SaaS CMS proof-of-concept (POC) blog series. In this post, we'll dive into extending a component within th...

Raghavendra Murthy | Jul 23, 2024 | Syndicated blog

Optimizely Graph – Faceting with Geta Categories

Overview As Optimizely Graph (and Content Cloud SaaS) makes its global debut, it is known that there are going to be some bugs and quirks. One of t...

Eric Markson | Jul 22, 2024 | Syndicated blog

Integration Bynder (DAM) with Optimizely

Bynder is a comprehensive digital asset management (DAM) platform that enables businesses to efficiently manage, store, organize, and share their...

Sanjay Kumar | Jul 22, 2024

Frontend Hosting for SaaS CMS Solutions

Introduction Now that CMS SaaS Core has gone into general availability, it is a good time to start discussing where to host the head. SaaS Core is...

Minesh Shah (Netcel) | Jul 20, 2024

Optimizely London Dev Meetup 11th July 2024

On 11th July 2024 in London Niteco and Netcel along with Optimizely ran the London Developer meetup. There was an great agenda of talks that we put...

Scott Reed | Jul 19, 2024