Yes, i'm using [Route("ajax/whatever")] from the System.Web.Mvc namespace (version: 5.2.3.0)
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:
[InitializableModule] [ModuleDependency(typeof(EPiServer.Commerce.Initialization.InitializationModule))] public class RoutingInitialization : IInitializableModule { public void Initialize(EPiServer.Framework.Initialization.InitializationEngine context) { var routes = RouteTable.Routes; routes.MapMvcAttributeRoutes(); CatalogRouteHelper.MapDefaultHierarchialRouter(routes, true);
Has anything significant changed to routing in the latest updates? My suspicion is that episerver is intercepting these routes somehow.
out of curiosity - when you install developer tools and go to routes section, what do you see there?
I'm not sure what you're asking here. What dev tools? What route section? Are you talking about RouteDebugger?
What Valdis is trying to say (he just forgot that everybody doesn't know what that is ;-) ) is that you should install this package:
https://nuget.episerver.com/package/?id=EPiServer.DeveloperTools
Read more about it here:
https://github.com/episerver/DeveloperTools
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.
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?
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`.
I would guess that it is some addon that is doing this.
Could you share the content of your packages.config?
packages.config
<?xml version="1.0" encoding="utf-8"?> <packages> <package id="Antlr" version="3.4.1.9004" 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="1.4.1.0" targetFramework="net451" /> <package id="DotNetZip" version="1.9.1.8" 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="1.0.0.0" 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="4.0.0.315" targetFramework="net461" /> <package id="structuremap.web-signed" version="3.1.6.186" targetFramework="net452" /> <package id="structuremap-signed" version="3.1.9.463" 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="2.0.2.13022" 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" /> </packages>
aside from this topic... why do you need 2 major versions of StructureMap?
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="3.1.6.186" targetFramework="net452" />
<package id="structuremap-signed" version="3.1.9.463" 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
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 }; customConfig.AddRoutesFromAssembly(System.Reflection.Assembly.GetExecutingAssembly()); routes.MapAttributeRoutes(customConfig);
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 :)
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
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(); } } [InitializableModule] [ModuleDependency(typeof(EPiServer.Commerce.Initialization.InitializationModule))] public class RoutingInitialization : IInitializableModule { public void Initialize(EPiServer.Framework.Initialization.InitializationEngine context) { var routes = RouteTable.Routes; routes.MapMvcAttributeRoutes(new InheritedDirectRouteProvider());
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