MVC REST services in Umbraco 4

Create a Global.asax file for your Umbraco project. In the Application_Start method register the MVC routes:

protected void Application_Start()
  RouteTable.Routes.MapRoute("ServiceRoute", "Services/{controller}/{action}/{id}",
    new { controller = "Home", action = "Index", id = UrlParameter.Optional },
    new string[] { "Your.Namespace.For.Mvc.Controllers" });

Because Umbraco already contains an empty compiled Global.asax/HttpApplication class in the bin folder, you must delete the “bin/App_global.asax.dll” file. You might read other ways to register Application_Start events in Umbraco. However I never managed to get this to work.

You also need to instruct Umbraco to ignore URLs for the MVC controllers. In Umbraco’s web.config’s change the “umbracoReservedPaths” app setting:

  <add key="umbracoReservedPaths" value="~/umbraco,~/install/,~/Services/" />

Leave a Reply

Your email address will not be published. Required fields are marked *