How To Get The Home Page In Umbraco?

One common requirement on every Umbraco build is getting a reference to the homepage from your code. On most website builds, you may only have one node as the

  -- Homepage
    -- Page One
    -- Page Two
In these scenarios you can use this snippet to get the homepage from the Umbraco Helper:
One thing to note is that if you're trying to use the Umbraco Helper in a custom class etc.. outside of your web project, you may need to create your own one. You can do that with the following snippet:
var umbracoContext = Umbraco.Web.UmbracoContext.Current;
var umbraco = new Umbraco.Web.UmbracoHelper(umbracoContext);
If you have a slightly more complex website where you may have multiple websites in a single Umbraco instance, you have a complex mega-menu that needs to be defined in its own section or even a setting page to store global data.
  -- Homepage
    -- Page One
    -- Page Two
  -- Mega Menu
  -- Settings Page
The above code might not necessarily return the homepage as you have multiple pages at the content level. Instead, we would have to filter out the results. One way to do this is via the document type alias, using a hardcoded string is a bit risky in case a content editor ever updated the name. A safer approach is to use the homepages content id. In Umbraco, you go to the 'Properties' tab for the home page in the content section, Umbraco_document_type_id
    var rootNodes = Umbraco.TypedContentAtRoot();
    var homeNodeByAlias = rootNodes.First(x => x.DocumentTypeAlias == "umbHomePage");
    var homeNodeById = rootNodes.First(x => x.Id == 1077);    


In today's guide, we've covered how to get a reference to the homepage from the Umbraco 7 API. If you only have a single item at the top of your content tree, then you can simply use Umbraco.TypedContentAtRoot().First(). If you have more than one page located at that level, then you will need to filter the results to get the page you want. I would recommend using the Id property, but you could also use the document type alias or even the document type id.

Jon D Jones

Software Architect, Programmer and Technologist Jon Jones is founder and CEO of London-based tech firm Digital Prompt. He has been working in the field for nearly a decade, specializing in new technologies and technical solution research in the web business. A passionate blogger by heart , speaker & consultant from England.. always on the hunt for the next challenge

Back to top
var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-35662136-1']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + ''; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })();