Habitat Sitecore

Web Api And MVC Routes in Habitat sitecore project

First of all I would like to describe the main problem here which is creating Web API and MVC routes which will handle the corresponding requests correctly.

From  technology point Web API is designed on much more on Lower level then MVC, to be clear it is not better or worse but they are used for different things, however MVC is build on top of the Web Api.

But as the MVC comes on top of the Web API routes that are different first go through the MVC Routes and if they cannot be found then go deeper in the Web Api routes.

Imagine if you have  two routes with same names  /GetMyList in MVC and  /GetMyList in Web API, there is a big chance that the route handler will be confused.

In Sitecore regular instance you can just define the route with RouteTable.Routes.MapRoute() or RouteTable.Routes.MapHttpRoute() and because there is no other api routes they will work, however in habitat you need to be more careful which function do you use in order create route.

This is because habitat already comes with the a lot of different pipeline processors which are pre-configured and this can be a problem when mapping new routes especially if you don’t know or don’t consider the already mapped routes from habitat.

Best practice in habitat would be to separate the web api routes from MVC routes and also always use the MapHttpRoute for Web API and MapRoute For MVC.

Keep in mind that one other good practice is to always separate Web API and MVC routes in separate folder and also the names of the routes should bed different. Please see the attached picture.

One thing I forgot to mention which is really important is that in habitat for every project have you maps the Web Api or MVC routes in the  RegisterWebApiRoutes.CS in the pipeline folder of that project, and normally  add the “pipeline”(RegisterWebApiRoutes.cs) to the pipeline processor in app_config/include/feature/nameOftheProject.Config in order to be properly executed and register the proper routes.

I hope that you will find this post useful and it will give you boost up if you stuck with Web Api and MVC Routes in Habitat project.


Habitat Sitecore

Install habitat on Sitecore 8.2 Instance

Hi as I mentioned in the introduction to Habitat post I would like to note some things on installing Habitat basically what do you need to take care and know before starting.

First of all and most easiest one is downloading the habitat solution from GitHub and you can do at least in two ways.

  1. If you know how to use Git then it is better just to download the repository from and Put it in the C:\projects\Habitat\ ( you can change this paths but you will need to adjust the paths in the Gulp Configuration.
  2. Download the code from GitHub through the Clone or download button and extract it on the mentioned folder C:\projects\Habitat\ ( this seems straight forward but it is a little bit tricky)
    The problem is that when you download the you need to unblock it before extracting it to the directory, since this file is downloaded from internet if you skip this step you will have 10000 files that you need to go one by one and click properties and unblock them. However the solution for this is just to unblock the zip archive  before extracting it as you can see on the picture.
  3. All you have to do now  is to follow the steps from the ( I have copied from here ) but please check my notes :

To install:

  1. Clone this repository to your local file system.   We have covered this already }
  2. (optional) Configure your settings if you are using settings other than the defaults:
    • The default settings for Habitat are
      • URL:
      • Location: C:\Websites\\
        { It is easier if you don’t use the C:\ Driver especialy on versions later then windows 7. C drive has a lot of protection and you will need to change permissions to a lot of files }
        I have used as Location : E:\wwwroot\alexU1\Website and I left the URL to be same
        Here is Picture from IIS and Explorer on how it looks like

    • To change the standard location of the source files, website files and website URL, modify the following files:
      • Please be aware to include or omit trailing slashes – as per the default
      • /Solution Items/src/Project/Habitat/code/App_Config/Include/Project/z.Habitat.DevSettings.config
      • /Solution Items/gulp-config.js
      • /Solution Items/publishsettings.targets
  3. Set up a clean Sitecore install with the settings from the previous step { It must be a clean install please check all the requirements before starting the process}
    • We recommend using Sitecore Instance Manager for the install. { I have used the normal .exe install however SIM is much more better for installing and creating backups}
    • Please note that the Sitecore executable installer does not support periods in the domain name and therefore if you are installing using this, please change the default domain (see step 2){ I changed the IIS bindings and site name manually }
    • Habitat requires:
      • Sitecore Experience Platform 8.2 Update 1 in Experience Platform or Experience Management mode
      • Webforms for Marketers 8.2 Update 1 module. It should be installed prior to running Sync Unicorn gulp task. Also you may need to have running mongo instance when installing WFFM module, otherwise it may lead to never ending installation dialogue window.
      • {Make sure that you have mongo runing while you are installing sitecore, it will not install without it – Webforms for Marketers 8.2 Update 1  this is a must, ig somehow the  taks (05-Sync-Unicorn runs a complete synchronization of Unicorn for all projects in the right order ) is failing probably it is missing the webforms or it have problems with permsions or read – only files }
  4. Restore Node.js modules
    • Make sure you have version 4+ of node.js Download here
    • In an elevated command window run ‘npm install’ in the root of repository.
  5. Build and publish the solution
    • Open an command window with elevated privileges and run ‘gulp’ in the root of repository.
    • Alternatively:
      • Open Visual Studio 2015 in Administrator Mode
      • Open the Visual Studio 2015 Task Runner Explorer pane (View | Other Windows | Task Runner Explorer).
      • Switch to “Solution ‘Habitat'”
      • Run the “default” task

That should be it, everything else should be as it is described on the Getting Started

Please keep in mind the following things and settings :
1. Unblock, Make Sure permissions are set correctly
2. Get all dependencies and requirements
3. Make sure that everything you run is as Administrator
3. Make sure that you have set proper paths to the Gulp Configs
Source location: C:\projects\Habitat\ 
Website location: C:\websites\\
Website URL:
To change the standard location of the source files, website files and website URL, modify the following files:

  • Please be aware to include or omit trailing slashes – as per the default
  • /Solution Items/src/Project/Habitat/code/App_Config/Include/Project/z.Habitat.DevSettings.config
  • /Solution Items/gulp-config.js
  • /Solution Items/publishsettings.targetsHere are the 2 picture where everything is stored on my machine and may Gulp config files


Publishing targets


I hope that this will help you


What is habitat

Refereeing the the GitHab repository for Habitat ( )

Habitat is a Sitecore solution example built on a modular architecture. The architecture and methodology focuses on:

  • Simplicity – A consistent and discoverable architecture
  • Flexibility – Change and add quickly and without worry
  • Extensibility – Simply add new features without steep learning curve

Habitat Makes implementation of new functionality in Sitecore much more easier and is also good practice for enterprise solution and developing your Sitecore solution with the proper Sitecore Helix guidelines.

There is a lot of documentation how to setup the Habitat project on your sitecore instance written on net, however the installation can be a little bit tricky and you could easily waste a lot of time. Once it is setup correctly it works as charm.

I will try to write some tutorial on how to install habitat ( adapt the already existing one, withe detailed explanation for the tricky parts ).

Meanwhile , you can find a lot of information on the provided videos and links below.

For more information about the architecture and the principles and conventions behind it, please see the Sitecore Helix guidelines

Video introductions:

  1. Architecture Introduction: Video
  2. Introduction to Modules: Video
  3. Introduction to Layers: Video


Also very good documentation on the Sitecore Helix guidelines.

And here is example of the how page should look like when you install Habitat  over your Sitecore instance.