ASP.NET Web API routes not working in Sitecore 7.5

Reason

After upgrading to Sitecore 7.5, some or all of your Web API routes have stopped working.
A new pipeline step in the initialize pipeline might be your problem.
The pipeline step (re-)configures Web API routes, overriding some (all?) previously configured routes and/or handlers.
It is patched into the initialize pipeline via the config include file “/App_Config/Include/Sitecore.Services.Client.config” (search for ServicesWebApiInitializer).

You may experience this issue if some or all of the following apply to your project:

  • You’re registering Web API routes via the Sitecore initialize pipeline, likely inspired by Patrick Delancy’s excellent article on the subject.
  • You’re not using a Sitecore include file, e.g. you’ve inserted your route registration pipeline step directly into the Web.config file.
  • Your route registration pipeline step is patched in before the new ServicesWebApiInitializer for any reason, e.g. you’ve explicitly patched in your pipeline processor after the Sitecore.Mvc.Pipelines.Loader.InitializeRoutes pipeline step.

The project where I’ve experienced this issue uses a custom IHttpControllerSelector implementation which was removed/replaced by the new pipeline step.

Code

  1. Continue to use Patrick Delancy’s excellent solution.
  2. Place the config include file described in Patrick’s article in a subdirectory of the “/App_config/Include” folder, to ensure it’s included after “/App_Config/Include/Sitecore.Services.Client.config” — e.g. save it as “/App_config/Include/My-Company/WebApiRoutes.config”.
  3. Use /sitecore/admin/showconfig.aspx to verify that your route registration processor is patched in after the ServicesWebApiInitializer.

Example

As mentioned above the important thing is to register your routes after the Sitecore.Services.Infrastructure.Sitecore.Pipelines.ServicesWebApiInitializer pipeline step when running Sitecore 7.5.
The Sitecore 7.5 initialize pipeline vs. the old Sitecore 7.2 version are shown below, MVC and Web API route registration steps highlighted for convenience.

Sitecore 7.5 initialize pipeline

Sitecore 7.5 initialize pipeline

Sitecore 7.2 initialize pipeline

Sitecore 7.2 initialize pipeline

Advertisements