Has anybody setup web api 2 attribute routing with 8.2 initial release? I tried the 'official' route, which is to create a custom pipeline handler to the initialize pipeline that does the registration. I've tried to hook it up with a config as well as using webactivator. I've done something similar to this: http://wp-bartbovendeerdtcom.azurewebsites.net/sitecore-8-webapi-v2-mvc-and-attribute-routing/ - In both cases, I get an error

"A route named 'MS_attributerouteWebApi' is already in the route collection". 

I've also used a marketplace module (https://marketplace.sitecore.net/Modules/A/Attribute_Routing_Support.aspx?sc_lang=en), which is essentially the same thing, but hooked up with a config. All same error.

It makes me think that a web api registration is happening somewhere else already in Sitecore registrations, but I'm not sure where. Even if it does, how do I get past this?

Ideas?

  • 1
    This error indicates to me that the 'config.MapHttpAttributeRoutes()' method is called multiple times. Did you scaffold your solution from a Visual Studio MVC/Web API template? You might want to double-check that you're not calling this twice - like for instance, once in your global.asax, and once in your web-activator code – Chris Smith Oct 14 '16 at 20:18
up vote 12 down vote accepted

This should actually now work out of the box on a clean 8.2 install.

Among the resolved issues from the 8.2 release notes:

​Sitecore.Services.Client prevents using Attribute Routing with ASP.NET WebAPI​.

Sitecore is calling the config.MapHttpAttributeRoutes() from Sitecore.Services.Client in the initialize pipeline. This is the one throwing the error you are seeing if you have already called that method in your own startup logic which is run first.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.