Did you know of the GetSettingsFromPage() method?
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:
The ironic part is that I found the solution while searching and finding an old blog post written by myself… (!).