Try our conversational search powered by Generative AI!

Attribute routing in CMS 11.7/mvc 5


I cannot seem to get attribute routing working in the latest CMS 11.7 with MVC5.  I keep getting 404.  I tried with a bare bones mvc5 application and it works fine.  I am calling the MapMvcAttributeRoutes method on routing initialization and no luck.  This did work perfectly with the AttributeRouting nuget package installed when we were on CMS 9.x

public virtual JsonResult Something()

public class RoutingInitialization : IInitializableModule
public void Initialize(EPiServer.Framework.Initialization.InitializationEngine context)
var routes = RouteTable.Routes;

Jun 01, 2018 16:06

and you are using `Route` class from the right namespace...?!

Jun 02, 2018 23:09

Yes, i'm using [Route("ajax/whatever")] from the System.Web.Mvc namespace (version:

I've baffled because I can create a bare bones MVC5 web site locally and it works perfectly.  I'm wondering if something in the way we register routes through epi's initialization modules is being intercepted.  Kind of at a loss here.

Below is the start of our route initialization:

    public class RoutingInitialization : IInitializableModule
        public void Initialize(EPiServer.Framework.Initialization.InitializationEngine context)
            var routes = RouteTable.Routes;


            CatalogRouteHelper.MapDefaultHierarchialRouter(routes, true);

Jun 04, 2018 1:16

Do you have stuff like the A/B-testing AddOn installed?

Jun 04, 2018 6:57

A/B testing AddOn is NOT installed

Jun 04, 2018 16:13

Has anything significant changed to routing in the latest updates?  My suspicion is that episerver is intercepting these routes somehow.

Jun 04, 2018 21:08

out of curiosity - when you install developer tools and go to routes section, what do you see there?

Jun 04, 2018 21:13

I'm not sure what you're asking here.  What dev tools?  What route section?  Are you talking about RouteDebugger?

Jun 04, 2018 21:29

What Valdis is trying to say (he just forgot that everybody doesn't know what that is ;-) ) is that you should install this package:

Read more about it here:

After that you get a new menu Item called Developer Tools and a sub menu item called Routes where you can see all routes that are registred.

Jun 04, 2018 21:34

yes, sorry for being lazy bastard

Jun 04, 2018 21:42

Thank you, I installed this nuget and was able to see all registered routes.  NO routes that are registered via [Route("whatever")] are shown.  I saw this as well in the route collection in the debugger.  The only routes that show are episerver routes and custom routes we register with routes.MapRoute().  So, what could be either ignoring or removing these routes?

Jun 04, 2018 22:12

I can verify that it IS working in Alloy based on 11.7 epi. you should look I guess somewhere else. Routes are registered in routing table after `MapMvcAttributeRoutes`.

Jun 05, 2018 6:34

I would guess that it is some addon that is doing this.

Could you share the content of your packages.config?

Jun 05, 2018 7:02


<?xml version="1.0" encoding="utf-8"?>
  <package id="Antlr" version="" targetFramework="net40" />
  <package id="AuthorizeNet" version="1.9.4" targetFramework="net461" />
  <package id="BundleTransformer.CleanCss" version="1.9.35" targetFramework="net451" />
  <package id="BundleTransformer.Core" version="1.9.35" targetFramework="net451" />
  <package id="BundleTransformer.Less" version="1.9.35" targetFramework="net451" />
  <package id="Castle.Core" version="4.2.1" targetFramework="net461" />
  <package id="Castle.Windsor" version="4.1.0" targetFramework="net461" />
  <package id="Common.Logging" version="3.3.1" targetFramework="net452" />
  <package id="Common.Logging.Core" version="3.3.1" targetFramework="net452" />
  <package id="CookieVisitorGroupCriteria" version="11.0.0" targetFramework="net461" />
  <package id="CouchbaseNetClient" version="2.3.11" targetFramework="net452" />
  <package id="dotless" version="" targetFramework="net451" />
  <package id="DotNetZip" version="" targetFramework="net40" />
  <package id="EntityFramework" version="6.2.0" targetFramework="net452" />
  <package id="EPiServer.CMS" version="11.8.0" targetFramework="net461" />
  <package id="EPiServer.CMS.AspNet" version="11.8.0" targetFramework="net461" />
  <package id="EPiServer.CMS.Core" version="11.8.0" targetFramework="net461" />
  <package id="EPiServer.CMS.TinyMce" version="2.2.0" targetFramework="net461" />
  <package id="EPiServer.CMS.UI" version="11.4.6" targetFramework="net461" />
  <package id="EPiServer.CMS.UI.Core" version="11.4.6" targetFramework="net461" />
  <package id="EPiServer.Commerce" version="12.2.0" targetFramework="net461" />
  <package id="EPiServer.Commerce.Core" version="12.2.0" targetFramework="net461" />
  <package id="EPiServer.Commerce.UI" version="12.2.0" targetFramework="net461" />
  <package id="EPiServer.Commerce.UI.ManagerIntegration" version="12.2.0" targetFramework="net461" />
  <package id="EPiServer.DeveloperTools" version="3.2.0" targetFramework="net461" />
  <package id="EPiServer.Find" version="12.7.0" targetFramework="net461" />
  <package id="EPiServer.Find.Cms" version="12.7.0" targetFramework="net461" />
  <package id="EPiServer.Find.Framework" version="12.7.0" targetFramework="net461" />
  <package id="EPiServer.Framework" version="11.8.0" targetFramework="net461" />
  <package id="EPiServer.Framework.AspNet" version="11.8.0" targetFramework="net461" />
  <package id="EPiServer.Logging.Log4Net" version="2.2.2" targetFramework="net461" />
  <package id="EPiServer.Packaging" version="3.4.0" targetFramework="net461" />
  <package id="EPiServer.Packaging.UI" version="3.4.0" targetFramework="net461" />
  <package id="EPiServer.Search" version="9.0.1" targetFramework="net461" />
  <package id="EPiServer.ServiceLocation.StructureMap" version="2.0.1" targetFramework="net461" />
  <package id="EPPlus" version="4.1.1" targetFramework="net452" />
  <package id="JavaScriptEngineSwitcher.Core" version="1.2.0" targetFramework="net451" />
  <package id="JavaScriptEngineSwitcher.Msie" version="1.2.0" targetFramework="net451" />
  <package id="log4net" version="2.0.8" targetFramework="net461" />
  <package id="Lucene.Net" version="3.0.3" targetFramework="net452" />
  <package id="Microsoft.AspNet.Mvc" version="5.2.3" targetFramework="net461" />
  <package id="Microsoft.AspNet.Providers.Core" version="2.0.0" targetFramework="net452" />
  <package id="Microsoft.AspNet.Razor" version="3.2.3" targetFramework="net461" />
  <package id="Microsoft.AspNet.Web.Optimization" version="1.1.3" targetFramework="net451" />
  <package id="Microsoft.AspNet.WebApi" version="5.2.3" targetFramework="net452" />
  <package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net452" />
  <package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net452" />
  <package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.3" targetFramework="net452" />
  <package id="Microsoft.AspNet.WebPages" version="3.2.3" targetFramework="net461" />
  <package id="Microsoft.Bcl" version="1.1.10" targetFramework="net452" />
  <package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="net451" />
  <package id="Microsoft.Net.Http" version="2.2.29" targetFramework="net452" />
  <package id="Microsoft.Owin" version="3.1.0" targetFramework="net461" />
  <package id="Microsoft.Owin.Host.SystemWeb" version="3.1.0" targetFramework="net461" />
  <package id="Microsoft.Owin.Security" version="3.1.0" targetFramework="net461" />
  <package id="Microsoft.Owin.Security.Facebook" version="3.1.0" targetFramework="net461" />
  <package id="Microsoft.Owin.Security.Google" version="3.1.0" targetFramework="net461" />
  <package id="Microsoft.ReportViewer.Common" version="10.0.40219.1" targetFramework="net452" />
  <package id="Microsoft.ReportViewer.WebForms" version="10.0.40219.1" targetFramework="net452" />
  <package id="Microsoft.Tpl.Dataflow" version="4.5.24" targetFramework="net461" />
  <package id="Microsoft.Web.Infrastructure" version="" targetFramework="net452" />
  <package id="Microsoft.Web.Xdt" version="2.1.1" targetFramework="net451" />
  <package id="MicrosoftReportViewerWebForms_v10" version="1.0.0" targetFramework="net40" />
  <package id="MsieJavaScriptEngine" version="1.5.0" targetFramework="net451" />
  <package id="Newtonsoft.Json" version="10.0.3" targetFramework="net461" />
  <package id="NuGet.Core" version="2.6.0" targetFramework="net452" />
  <package id="Owin" version="1.0" targetFramework="net461" />
  <package id="SharpZipLib" version="0.86.0" targetFramework="net452" />
  <package id="StructureMap" version="4.5.2" targetFramework="net461" />
  <package id="structuremap.web" version="" targetFramework="net461" />
  <package id="structuremap.web-signed" version="" targetFramework="net452" />
  <package id="structuremap-signed" version="" targetFramework="net461" />
  <package id="System.ComponentModel.Annotations" version="4.4.0" targetFramework="net461" />
  <package id="System.Data.SqlClient" version="4.4.0" targetFramework="net461" />
  <package id="System.Reflection.Emit" version="4.3.0" targetFramework="net461" />
  <package id="System.Reflection.Emit.Lightweight" version="4.3.0" targetFramework="net461" />
  <package id="System.Security.AccessControl" version="4.4.0" targetFramework="net461" />
  <package id="System.Security.Cryptography.Xml" version="4.4.0" targetFramework="net461" />
  <package id="System.Security.Permissions" version="4.4.0" targetFramework="net461" />
  <package id="System.Security.Principal.Windows" version="4.4.0" targetFramework="net461" />
  <package id="System.Threading.AccessControl" version="4.4.0" targetFramework="net461" />
  <package id="System.ValueTuple" version="4.4.0" targetFramework="net461" />
  <package id="System.Web.Optimization.Less" version="1.3.3" targetFramework="net451" />
  <package id="Validation" version="" targetFramework="net461" />
  <package id="WebActivator" version="1.4.4" targetFramework="net40" />
  <package id="WebGrease" version="1.5.2" targetFramework="net40" />
  <package id="Zlib.Portable" version="1.9.2" targetFramework="net40" />
Jun 05, 2018 15:43

aside from this topic... why do you need 2 major versions of StructureMap?

Jun 05, 2018 15:49

One thing I see directly is that you should delete these packages since you do not need them when having Episerver 11

  <package id="structuremap.web-signed" version="" targetFramework="net452" />
  <package id="structuremap-signed" version="" targetFramework="net461" />

I also think these can be removed (if not Commerce use them)

  <package id="EPiServer.Packaging" version="3.4.0" targetFramework="net461" />
  <package id="EPiServer.Packaging.UI" version="3.4.0" targetFramework="net461" />

Other than that I can not see any package that will stop webapi routing to work

Jun 05, 2018 15:49

and episerver is 11.8 (not 11.7 as you mentioned in title)

Jun 05, 2018 15:50

I'm pretty certain we've identified the issue.  We have controllers with base controllers that have overridable actions.  The base controllers contain most of the functionality and is where the AR endpoints were located.  Another dev here pointed out we had to implement the following on startup to get around this.

var customConfig = new Configuration { InheritActionsFromBaseController = true };

I've confirmed that moving the endpoint to the child controller works.

Thanks all for your help, maybe this will help someone down the road, however this has nothing to do with EPiServer :)

Jun 05, 2018 19:54

Great that you solved it.
That is something I have not encounted so thanks for the info.

But please take Valdis and my advice to clean up within your packages, especially the Structuremap (remove the signed once) since that can give you some trouble

Jun 05, 2018 20:04

Absolutely, i've already done this, thank you.

SOLUTION (for anyone this may help)

I've created a custom DirectRouteProvider where I can set "inherit" = true.  This allow base controller action to get picked up.

public class InheritedDirectRouteProvider : DefaultDirectRouteProvider
    protected override IReadOnlyList<IDirectRouteFactory>GetActionRouteFactories(ActionDescriptor actionDescriptor)
        return actionDescriptor.GetCustomAttributes(typeof(IDirectRouteFactory), true).Cast<IDirectRouteFactory>().ToArray();

public class RoutingInitialization : IInitializableModule
    public void Initialize(EPiServer.Framework.Initialization.InitializationEngine context)
        var routes = RouteTable.Routes;
        routes.MapMvcAttributeRoutes(new InheritedDirectRouteProvider());
Jun 05, 2018 20:46

when you think more about inheritance problem - not registering inherited attributes makes sense actually. but I was not aware of this implementations details. thx for finding it out :)

Jun 05, 2018 20:59
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.