Skip to content

Accessing Umbraco data outside the Umbraco Request Pipeline

Andrew Morger edited this page Apr 18, 2016 · 1 revision

Why would you do such a thing?

The Umbraco Request Pipeline is a useful and necessary component of a standard Umbraco instance because it controls everything from routing to content and view resolution. Normally one would never want to circumvent these features of the framework. However, imagine for a moment that you would like to expose data that is housed within Umbraco in a manner that isn't a traditional website, such as a WebApi. How would you do it?

Enter Webless Umbraco

With the implementation of just 2 Umbraco core classes and a little config, it is very easy to setup an Umbraco application that can be run from any context (including a console app!) that can integrate with Umbraco through Vault.

Ok, you sold me. Now what?

Take a look at our Reference Website. This example has everything you need to get up and going. Here's a quick overview of what you need to do:

  1. Add a Nuget reference to UmbracoCms.Core
  2. Create the 2 Umbraco classes needed
  1. Create App_Data and config directories that these classes utilize
  2. Copy the config\umbracoSettings.config file from your current Umbraco instance (or use one from the vanilla install) example
  3. Update your web.config to add the UmbracoConfiguration section group and the settings section example
  4. Update your web.config file to include your Umbraco connection string and ensure it is named umbracoDbDSN
  5. During the startup of your web application, create an instance of your Umbraco ApplicationBase from above and call the .Start() method.
  • For an Owin hosting example, see here
  1. After you create the new Umbraco Application, be sure you override the UmbracoVault context by calling Vault.SetOverrideContext(new UmbracoWeblessContext());
  2. Enjoy

Limitations

There are some features of UmbracoVault that are not available within this context. This is due to

  • Lack of a concept of "Current", which is not available in this execution context.
  • Lack of API support for features we achieved using XPath queries
    • Since we are querying the database directly, we are no longer accessing data through the umbraco.config file, therefore the methods that were relying on XML and XPath queries to function are no longer supported.
    • Down the road if Umbraco adds Services to support this functionality, this will be restored.

The following methods will now throw a VaultNotImplementedException exception when running under the WeblessContext:

  • GetCurrent()
  • GetCurrent(Type type)
  • GetByDocumentType()
  • GetUrlsForDocumentType()
  • QueryRelative()