Try our conversational search powered by Generative AI!

Mari Jørgensen
Sep 27, 2010
  4795
(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
Optimizely and the never-ending story of the missing globe!

I've worked with Optimizely CMS for 14 years, and there are two things I'm obsessed with: Link validation and the globe that keeps disappearing on...

Tomas Hensrud Gulla | Apr 18, 2024 | Syndicated blog

Visitor Groups Usage Report For Optimizely CMS 12

This add-on offers detailed information on how visitor groups are used and how effective they are within Optimizely CMS. Editors can monitor and...

Adnan Zameer | Apr 18, 2024 | Syndicated blog

Azure AI Language – Abstractive Summarisation in Optimizely CMS

In this article, I show how the abstraction summarisation feature provided by the Azure AI Language platform, can be used within Optimizely CMS to...

Anil Patel | Apr 18, 2024 | Syndicated blog

Fix your Search & Navigation (Find) indexing job, please

Once upon a time, a colleague asked me to look into a customer database with weird spikes in database log usage. (You might start to wonder why I a...

Quan Mai | Apr 17, 2024 | Syndicated blog