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 theSitecore.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
- Continue to use Patrick Delancy’s excellent solution.
- 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”.
- 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.
A small note to the solution: It breaks parts of the new Sitecore 8 UI, as it relies on an existing custom IHttpControllerSelector introduced by Sitecore (NamespaceHttpControllerSelector).
A fix to this is to extend Sitecores NamespaceHttpControllerSelector and make sure that the SelectController-method of the extendes class always calls the base-class if no connector is found.